Вы пытаетесь декодировать неверную строковую ошибку JSON - PullRequest
0 голосов
/ 18 мая 2018

Я пытаюсь вывести Grid из источника SQL с помощью PHP, но он не работает.

Вот ошибка, которую я получаю в консоли:

[W] For WAI-ARIA compliance, IMG elements SHOULD have an alt attribute.
[E] Ext.JSON.decode(): You're trying to decode an invalid JSON String: 
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>242280</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php' bgcolor='#eeeeec'>...\Read_employee.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>242280</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php' bgcolor='#eeeeec'>...\Read_employee.php<b>:</b>0</td></tr>
</table></font>
[{"id":null,"firstname":"Alain","lastname":"Doyon","title":"Project Manager","businessunit":"Dev","experience":"7"},{"id":null,"firstname":"Joel","lastname":"Deslauriers","title":"Integrator Senior","businessunit":"Kappa","experience":"5"}]

Вот мой PHP-файл:

<?php
require_once"..//..//_includes/headers.php";



$query = "select firstname, lastname, title, businessunit, experience from 
employee_tab order by businessunit";
logit($query);
$result = odbc_exec($connection,$query);
$cnt = 0;
while($row = odbc_fetch_array($result))

{ 
$cnt = $cnt + 1;
$myArray[] = array(
    'id'=>$row['id'],
    'firstname'=>$row['firstname'],
    'lastname'=>$row['lastname'],
    'title'=>$row['title'],
    'businessunit'=>$row['businessunit'],
    'experience'=>$row['experience'],
    );


}

if (isset($myArray))
{
    if ( sizeof($myArray) > 0 )
    {
        $output = json_encode($myArray);
        echo $output;
    }
    else
    {
        echo '(success:true,"error":0)';    
    }
}
else
    {
        echo '(success:true,"error":0)';
    }

?>

Спасибо за вашу помощь.

Ответы [ 2 ]

0 голосов
/ 18 мая 2018

Сообщение самоочевидно: Notice: Undefined index: id in C:\wamp64\www\EmployeeMenu\_data\employee\Read_employee.php on line <i>14</i>

Ваш запрос $ $ будет возвращать только столбцы «имя, фамилия, заголовок, подразделение, опыт», а не «идентификатор», но вы используете ['id'] в цикле while.Эт паф, предупреждение!

0 голосов
/ 18 мая 2018

Вы получаете это, потому что у вас включен display_errors, и поэтому вы получаете предупреждения о вещах, повреждающих ваш JSON.

Выключите его в своем php.ini

Лучший опыт регистрации ошибок - это запись журнала в терминал без отображения на экране.

Выполните isset() Для начала проверьте файл Read_employee.php в строке 14!Удачи

...