Note that there are some explanatory texts on larger screens.

plurals
  1. POUncaught SyntaxError: Unexpected token ::
    text
    copied!<p>In my application I get a Uncaught SyntaxError: Unexpected token : when using getJSON to fetch JSON from server. </p> <p>This is the javascript I use: </p> <pre><code>$('#employeeListPage').bind('pageinit', function(event) { getEmployeeList(); }); setInterval ( "getEmployeeList()", 10000 ); var vanhadata = ""; function getEmployeeList() { $.getJSON(serviceURL + 'getemployees.php?autonumero=' + autonumero + 'callback=?', function(data) { if(JSON.stringify(data) != JSON.stringify(vanhadata)){ $('#employeeList li').remove(); employees = data.key; $.each(employees, function(index, employee) { $('#employeeList').append('&lt;li&gt;&lt;a href="keikka.html?id=' + employee.IND + '"&gt;' + '&lt;h4&gt;' + employee.OSO + '&lt;/h4&gt;' + '&lt;img src="pics/' + employee.TILA + '.png"/&gt;' + '&lt;p&gt;' + employee.AIKA + '&lt;/p&gt;' +'&lt;/a&gt;&lt;/li&gt;'); }); $('#employeeList').listview('refresh'); if(vanhadata != "") alert("Uusia keikkoja!"); vanhadata = data; } }); } </code></pre> <p>The JSON response from the server seems to be right but it shows error and no data is displayed. Console also prints: <code>"Resource interpreted as Script but transferred with MIME type text/html:"</code> </p> <p>This is the JSON response:</p> <pre><code>{ "key": [ { "NIMET": "Tuntematon", "PERHJAS": "0", "SAATTAJA": "0", "m_yht": "0", "OSO": null, "AIKA": "2010-03-11 10:00:00", "OSOITELAJI": "0", } ] }UncaughtSyntaxError: Unexpectedtoken: </code></pre> <p>And the getemployees.php:</p> <pre><code>&lt;?php header('Content-Type: application/json; charset=UTF-8'); include 'config.php'; $number = $_GET['autonumero'] ; $sql = "select * from table where number=\"$number\""; try { $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh-&gt;query($sql); $employees = $stmt-&gt;fetchAll(PDO::FETCH_OBJ); $dbh = null; echo '{"key":'. json_encode($employees) .'}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e-&gt;getMessage() .'}}'; } ?&gt; </code></pre> <p>When modify PHP file to: </p> <pre><code> if ($_GET['callback']) print $_GET['callback']."("; echo '{"key":'. json_encode($results) .'}'; if ($_GET['callback']) print ")"; } catch(PDOException $e) { echo '{"error":{"text":'. $e-&gt;getMessage() .'}}'; } </code></pre> <p>The response I get is:</p> <pre><code>&lt;br /&gt; &lt;font size='1'&gt;&lt;table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'&gt; &lt;tr&gt;&lt;th align='left' bgcolor='#f57900' colspan="5"&gt;&lt;span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'&gt;( ! )&lt;/span&gt; Parse error: syntax error, unexpected T_CATCH in C:\Services\getemployees.php on line &lt;i&gt;40&lt;/i&gt;&lt;/th&gt;&lt;/tr&gt; &lt;/table&gt;&lt;/font&gt; </code></pre> <p>So it is not JSON at all.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload