JSON formatting error

JSON formatting error

nalinagcnalinagc Posts: 22Questions: 2Answers: 0

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.'
}';

«1

Answers

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    Can you please link to the page in question, as per the forum rules, or use the debugger.

    Allan

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    i tested code following url

    http://live.datatables.net/vesajodu/1/edit

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    ... and after you have followed the diagnostic steps set out at that link, you will know how your server is responding.

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    hi tangerine
    while following steps it shows error

    event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

    jquery.js

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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 .....

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    Can you using the debugger or link to the page please?

    Allan

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    if click over DataTables debug" button
    it shows
    DataTables debug bookmarklet
    DataTables is not available on this page.

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    debug code: iqemop

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    hi allan

    debug code iqemop

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0
    edited December 2014

    hi

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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 ?

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    plz find my sample code

    header('Content-Type: application/json');
    $res = arrayPHPToJS($rets);

    echo '{ "sEcho": "2", "iRecords": '.count($rets).', "iDisplayRecords": '.count($rets).', "aaData": '.$res.' }';

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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).',

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    how to parse single quote { "sEcho": "2", "iRecords": '.count($rets).', "iDisplayRecords": '.count($rets).', "aaData": '.$res.' }

    You can't - that isn't valid JSON. It looks like the PHP hasn't been executed.

    Allan

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    instead of ' quote if i use " quote php values are not active
    plz suggest me is there any way to achieve this

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    Are you actually executing the PHP? The code looks fine for PHP code.

    Allan

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    yes
    and values are fetching from MySQL db,
    it shows
    pop up message
    Data tables warning table id = examples_table

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    efemot

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    code:
    efemot

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    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

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    hi allan

    thanks for your support
    plz send any related URL to fix my issues

  • nalinagcnalinagc Posts: 22Questions: 2Answers: 0

    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()

  • allanallan Posts: 61,617Questions: 1Answers: 10,089 Site admin

    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

This discussion has been closed.