JSON formatting error
JSON formatting error
hi all,
i am new to json , running applications using wamp server ( localhost )
but if open application it shows
pop up message
DataTables warning (table id = 'examples'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
php code
header('Content-Type: application/json');
$res = arrayPHPToJS($rets);
echo
'{
"sEcho": "2",
"iRecords": '.count($rets).',
"iDisplayRecords": '.count($rets).',
"aaData": '.$res.'
}';
Answers
Can you please link to the page in question, as per the forum rules, or use the debugger.
Allan
i got this pop up message
Data tables warning table id = examples_table – ajax error for more informations
About this error , plase see http://datatables.net/tn/7
i tested code following url
http://live.datatables.net/vesajodu/1/edit
... and after you have followed the diagnostic steps set out at that link, you will know how your server is responding.
hi tangerine
while following steps it shows error
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
jquery.js
i got one more error from jquery.js file
plz send URL to download jQuery JavaScript Library v1.10.2
Uncaught SyntaxError: Unexpected token < jquery.js:550
jQuery.extend.parseJSON jquery.js:550
fire jquery.js:3048
self.fireWith jquery.js:3160
done jquery.js:8235
callback
i followed diagnostic steps and click over response tab
it shows output;
{"sEcho":"2","iTotalRecords":2,"iTotalDisplayRecords":2,"aaData": [["C++", 3, 3, 0], ["php", 1, 1, 0]]}
but if i open applications through browser
display without data
shows only
processing ...
loading .....
Can you using the debugger or link to the page please?
Allan
if click over DataTables debug" button
it shows
DataTables debug bookmarklet
DataTables is not available on this page.
debug code: iqemop
hi allan
debug code iqemop
help me out this error ,
Uncaught SyntaxError: Unexpected token < jquery.js:550
jQuery.extend.parseJSON jquery.js:550
(anonymous function) home.php:209
fire jquery.js:3048
self.fireWith jquery.js:3160
done jquery.js:8242
callback
There doesn't appear to be any such debug code. Can you please link to the page so I can debug it and offer some help.
Allan
i don't know how to link page and all
Uncaught SyntaxError: Unexpected token <
line no 550
parseJSON: function( data ) {
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );
using jQuery JavaScript Library v1.10.2
hi
Thank you for the debug code. From hat it is quite clear that the data being returned from the server is not valid JSON. To see the returned data click the "Tables" button at the top and then the "Server interaction" option for the first table.
Your
core/up_exams.php
script is not producing valid JSON, which is what is causing the issue.core/up_exams.php
needs to be fixed.Allan
hi allan
thanks for your support
up_exams.php was no data in MySQL it was empty tables
what about other files ,
how i need to fix this error ?
plz find my sample code
header('Content-Type: application/json');
$res = arrayPHPToJS($rets);
echo '{ "sEcho": "2", "iRecords": '.count($rets).', "iDisplayRecords": '.count($rets).', "aaData": '.$res.' }';
how to parse single quote
{
"sEcho": "2",
"iRecords": '.count($rets).',
"iDisplayRecords": '.count($rets).',
"aaData": '.$res.'
}
http://jsonlint.com/
Parse error on line 3:
...2", "iRecords": '.count($rets).',
You can't - that isn't valid JSON. It looks like the PHP hasn't been executed.
Allan
instead of ' quote if i use " quote php values are not active
plz suggest me is there any way to achieve this
Are you actually executing the PHP? The code looks fine for PHP code.
Allan
yes
and values are fetching from MySQL db,
it shows
pop up message
Data tables warning table id = examples_table
All I can say is that based on the debug trace you gave above, the server is not returning valid JSON. Without access to the server I can't say why that is. You'll need to debug the script there.
Allan
efemot
code:
efemot
I'm not sure what you expect me to do with the debug trace? It also shows the same JSON formatting error. The data being returned form the server simply is not JSON.
Allan
hi allan
thanks for your support
plz send any related URL to fix my issues
i found these two error in log file
PHP Warning: array_keys() expects parameter 1 to be array, integer given in
PHP Warning: Invalid argument supplied for foreach()
You just sent me an e-mail with a screenshot of a debug code - thanks for that.
It shows that you have configured DataTables to use an object data source (
mData: "id"
etc) but your JSON from the server doesn't contain objects, it has arrays. You need to either remove the mData options, or use objects in the JSON return.Allan