DataTables logo DataTables

DataTables warning: JSON data from server could not be parsed.
  • For some reason, this just started happening. I am getting this error when trying to load in my JSON data with AJAX:
    "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error."

    Firebug is giving this error:
    Invalid label
    {"aaData:" [

    Here is the HTML, JS and JSON. I have no idea what happened or why...does anyone here?

    Table HTML:
     
       <table id="test_table">
            <thead>
                <tr>
                    <th>One</th>
                    <th>Two</th>
                    <th>Three</th>
                    <th>Four</th>
                    <th>Five</th>
                    <th>Six</th>
                    <th>Seven</th>
                </tr>
            </thead>
            <tbody>
    
            </tbody>
        </table>
    
    Javascript:
        $('#test_table').dataTable({
            "sAjaxSource" : 'dt_ajax.txt'
        });
        

    JSON Data:
    {"aaData": [
          [
              "<img src=\"images/details_open.png\">",
              "3S",
              "38",
              "09",
              "300000",
              "500000",
              "Test data"
          ],
          [
              "<img src=\"images/details_open.png\">",
              "5I",
              "34",
              "12",
              "500000",
              "1000000",
              "aaaaa"
          ],
          [
              "<img src=\"images/details_open.png\">",
              "Jumbo",
              "9",
              "8",
              "888888",
              "8888888",
              "testtt"
          ]
    ]}
    

    Thanks in advance! P.S. The data works fine when input directly. Only "sAjaxSource" is getting this error.
  • I have exactly the same problem.
    On my side it is related to the Jquery version change.
    With Jquery 1.4.4 it works fine, but in 1.5 i have the above said error
  • I have JSON parse errors from time to time as well; since my application is polling every few seconds, I just let my application ignore the errors (modified it so that an alert box does not appear). I am also using jQuery 1.5. I did not test extensively in 1.4.x before switching to 1.5 because I started using DataTables close to the same time that 1.5 came out.

    Interestingly, though, I only rarely get the parse error. Code is almost entirely logical, meaning that in a controlled environment, results should either consistently fail or consistently succeed. I'm not sure why it only *periodically* fails to parse properly for me, but I have to admit I have always simply believed that it was the factor OUT of my control (the communication channel between client and server) that was causing the failure, rather than jQuery or DataTables.

    Now that I'm thinking about it more carefully, though, it's worth mentioning that my parse errors almost always happen near initial page load.

    Since JavaScript executes asynchronously, I wonder if in some scenarios there is a timing issue. I am retrieving my JSON with AJAX and server-side processing, and perhaps it's usually taking Juuuuust long enough to get the data; whereas reading it in with a simple HTTP request in the initialize object (dt_ajax.txt), the data arrives before other relevant functions have terminated...? Subsequent refreshes don't need to build the entire DOM from scratch, so the timing of activity for fetching data and rendering the page will be different; something about that difference makes it less likely that I see a parse error once I'm past the initial page load.

    It's just a guess out of the blue, I do wonder if there's a timing issue somewhere.

    Greg
  • Did some quick testing; dropped in 1.4.4, and refreshed my page several times (to force initial page load which is where I usually see the error).

    About one in ten times, I still see the error. Swapped back in 1.5, and same results.. the error didn't seem to appear (for me at least, with my particular environment) any more or less frequently.

    I'm not 100% sure what conclusion to draw. You don't want JSON parse errors EVER, but as I said before I just let my application ignore them when they do appear. But I don't see 1.5 being worse than 1.4.4 in my scenario. They BOTH actually produce a parse error from time to time. It could still be timing... in 1.5, they no doubt refactored certain functions (and I know they overhauled the AJAX module) which might make the error appear more consistently in your particular scenarios.
  • Another thread discussing this: http://datatables.net/forums/comments.php?DiscussionID=3993&page=1#Item_16 . Are you using the validation plug-in for jQuery - that appears to cause the issue you are seeing with jQuery 1.5.

    Allan
  • Yes indeed it was the Validation plug-in. Thank you all for your help!
  • Okay, it might be the validation plugin-in, but HOW to deactivate or in general: How to solve this big issue?
  • Two ways: 1. remove the validation plug-in, 2. upgrade to the very latest validation plug-in code ( https://github.com/bigfix/jquery-validation/commit/9aa53f9241224ba349f9fe1b2c801be0f431b63b ). There are quite a few discussions on the web about this issue with jQuery 1.5 and the jQuery validation plug-in ( http://www.google.com/#q=jquery+1.5+validate ). Basically it appears that the plug-in wraps and overwrites the $.ajax stuff, thus causing the problem since Ajax for an overhaul in jQuery 1.5.

    Allan
  • hello i have the same problem...but iam not able to find out where or how i can disable the validate plug in. i don kno if i hav one. where should i look to find it out. i use jquery.dataTables.min 1.7.6 and jquery.js is 1.2.6. and i am testing on firefox. i print the response in my log4j and the format looks correct.please help.
    my response looks like this:

    { "sEcho": 1, "iTotalRecords": 10, "iTotalDisplayRecords": 10, "aaData": [ ["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"],["1","medata","001","1","tom"] ] }

    -medSwa
  • DataTables required jQuery 1.3 or newer due to some of the calls made. If you can upgrade that, I would do so.

    Allan
  • Hi Allan,

    I've the same issue above. I just doing some test and use your jquery & datatables from your server
    http://datatables.net/release-datatables/media/js/jquery.js - jQuery v1.7.1
    http://datatables.net/release-datatables/media/js/jquery.dataTables.js - 1.9.0

    and below are my json data format and validated already through www.JSONLint.com
    {
        "sEcho": 0,
        "iTotalRecords": "34635",
        "iTotalDisplayRecords": "34635",
        "aaData": [
            [
                "MT",
                "RTWWA",
                "Kita liat aja nanti asjjdasjjasjfjasfjjajasjfjasjf",
                "Kita liat aja nanti asjjdasjjasjfjasfjjajasjfjasjf",
                "Kita liat aja nanti asjjdasjjasjfjasfjjajasjfjasjf"
            ],
            [
                "wrwr",
                "dsfdsg",
                "ewrewr",
                "ewrewr",
                "ewrewr"
            ],
            [
                "wrwer",
                "ewrew",
                "ewrew",
                "ewrew",
                "ewrew"
            ]
        ]
    }
    

    but I got Browser Error Message "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error".

    could you advise me what's the problem of this issue above?

    Thanks in advance.
  • Hi Allan,

    Just ignore my question above. the problem solved, already. Thanks!
  • Hello Allan,

    "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error".
    could give me the solution ? my json data format from server. but my data comes in body. i could not display the data in table. could you help me?
  • could give me the solution ?

    Absolutely - use correctly formatted JSON ;-).

    In all seriousness, use http://jsonlint.com to find out why your JSON isn't valid and firebug to get the JSON reply from the server.

    Allan
  • Hi Allan,
    congratulations for your excellent job.

    I am using
    jquery-1.7.1
    jquery.dataTables 1.9.0

    I have validated successful my JSON data using http://jsonlint.com
    and the same JSON data works fine on other jQuery / xhr calls.

    Do you see any other reasons about this issue?

    Thanks.

    Martin


    {
    "rows": [
    {
    "row": {
    "ID": "183",
    "Field1": "Barrett Rollins",
    "Field2": "1-759-171-2284",
    "Field3": "[email protected]",
    "Field4": "311 Egestas Rd.",
    "Field5": "Vancouver",
    "Field6": "M3R 2HN",
    "Field7": "Taiwan, Province of China",
    "Field8": "nisi. Mauris nulla. Integer urna. Vivamus molestie dapibus ligula. Aliquam",
    "Field9": "Lorem ipsum dolor sit",
    "Field10": ""
    }
    },
    {
    "row": {
    "ID": "184",
    "Field1": "Lee Terrell",
    "Field2": "1-366-499-3352",
    "Field3": "[email protected]",
    "Field4": "Ap #498-1999 Consectetuer Rd.",
    "Field5": "Brookings",
    "Field6": "30324",
    "Field7": "Papua New Guinea",
    "Field8": "mauris a nunc. In at pede. Cras vulputate velit eu",
    "Field9": "Lorem ipsum dolor",
    "Field10": ""
    }
    }
    ]
    }
  • Are you using both mDataProp and sAjaxDataProp to tell DataTables to look at "rows" and the object parameters in your JSON?

    Allan
  • Hi, I tested my JSON and it's valide but i have this error when i try to use datatbles to show my data: "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error".

    Any help please????
  • Please run your table throughout he debugger and link me to the result.

    Allan
  • I consistently get this error when logging out of my website and leaving a page that has an automatically updating DataTable. I suspect it has something to do with leaving the page during a data poll.
  • Very probably yes - are you using Firefox, I've notice this happening there before. What you could do is set DataTables to exception rather than 'alert' error mode:

    $.fn.dataTableExt.sErrMode = 'throw';
    

    Allan
  • a have the samoe error: DataTables warning: JSON data from server could not be parsed
    php returns this json
    {

    "sEcho":0,
    "iTotalRecords":"933",
    "iTotalDisplayRecords":"933",
    "aaData":[
    [
    {
    "firm_name":"ЕЛЕКТРОСНАБДЯВАНЕ",
    "date_ot":"15.09.1979",
    "altnameto":"01.12.1987",
    "kodnkpd":"74122009",
    "dlujnost":"Електромонтьор"
    },
    {
    "firm_name":"ТКСС ТЕЛЕКОМПЛЕКТ",
    "date_ot":"25.02.1988",
    "altnameto":"09.10.1989",
    "kodnkpd":"31153019",
    "dlujnost":"Техник механик съобщителни и свързочни съоръжения"
    },
    {
    "firm_name":"ЕЛЕКТРОРАЗПРЕДЕЛЕНИЕ ВАРНА АД",
    "date_ot":"19.10.1989",
    "altnameto":"29.12.2005",
    "kodnkpd":"74122009",
    "dlujnost":"Електромонтьор"
    },
    {
    "firm_name":"ЕНЧЕВ ТРАНС ЕООД",
    "date_ot":"11.10.2006",
    "altnameto":"05.12.2007",
    "kodnkpd":"52430001",
    "dlujnost":"Пласьор стоки"
    }
    ]
    ]

    }

    and the JS

    <script type="text/javascript" charset="utf-8">
    $(document).ready(function() { $('#table_rabotni_mesta').dataTable( {"bProcessing": true, "bServerSide": true, "sAjaxSource": "table_server.php", "sServerMethod": "POST",
    //ColReorder
    "sDom": 'T<"clear">Rlfrtip',
    "bJQueryUI": true, "sPaginationType": "full_numbers",

    //translation plugin
    "oLanguage": { "sUrl": "../lang/dataTables.bg.txt"},

    "fnServerParams": function ( aoData ) {
    aoData.push( { "name": "table", "value": "" } );
    aoData.push( { "name": "blah", "value": "blahblah" } );
    aoData.push( { "name": "thing", "value": "thingsvalue" } );
    } } ); } );
    </script>

    here is the HTML:
    <table cellpadding="0" cellspacing="0" border="0" id="table_rabotni_mesta" class="display"><thead><tr><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td colspan="5" class="dataTables_empty">Зареждане на информацията от сървъра</td></tr></tbody><tfoot><tr><th></th><th></th><th></th><th></th><th></th></tr></tfoot></table>

    WHERE DID I GET WRONG???


    WHERE DD I GET WRONG
  • Please link us to the page.
  • And right enough the server is not returning JSON. It is returning:

    <pre>ORDER BY  p.firm_name as firm_name asc</pre><pre></pre><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>Error on expert-2002.com</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="author" content="еКсперт-2002"><meta name="company" content="eXpert-2002"><meta name="creator" content="www.expert-2002.com"><meta name="designer" content="www.expert-2002.com"><meta name="generator" content="Basic Site System"><meta http-equiv="Cache-Control" content="max-age=0"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Expires" content="Tue, 01 Jan 1980 1:00:00 GMT"><meta http-equiv="expires" content="-1"><meta http-equiv="Pragma" content="no-cache"><link rel="shortcut icon" href="multimedia/icon/logo.png" ><style type="text/css">body { color: #444444; background-color: #EEEEEE; }h1 { font-size: 2em; }h2 { font-size: 1.2em; }h3 { font-size: 1em; }#page{ background-color: #FFFFFF; width: 60%; margin: 24px auto; padding: 12px; }#header { padding: 6px ; text-align: center; background-color: #475076; color: #FFFFFF; }#content {   padding: 4px 0 24px 0; }#footer { color: #666666; background: #f9f9f9;  padding: 10px 20px; border-top: 5px #efefef solid; font-size: 0.8em; text-align: center; }#footer a { color: #999999; }</style></head><body><div id="page"><div id="header"><h1>FOUND ERROR !!!</h1></div><div id="content"><h3></h3><h2>Bad query extentions: </h2><h3>SELECT SQL_CALC_FOUND_ROWS p.firm_name as firm_name, DATE_FORMAT(p.date_ot, \'%d.%m.%Y\' )as date_ot, DATE_FORMAT(p.date_do, \'%d.%m.%Y\' )as altnameto, nkpd.kod_2012 as kodnkpd, nkpd.dlujnost as dlujnost FROM personal_staj p LEFT JOIN db_nkpd nkpd ON nkpd.id=p.id_nkpd  ORDER BY  p.firm_name as firm_name asc LIMIT 0, 10</h3><hr><address>More information about this may be available in the expert-2002.com server  error log.</address></div><div id="footer"><p>&copy;Copyright 2002-2012 <a href="http://expert-2002.com">eXpert-2002.com</a>; | дизайн и хостинг <a href="http://www.eXpert-2002.com"; target="_blank">еКсперт-2002</a></p></div></div></body></html>
    

    Allan
  • are you shure .. because i se the json format without those <pre>
    server file is http://expert-2002.com/multisys/support/table_server.php
  • 100% certain. Use Firebug and you'll see what the server is responding with.

    Allan
  • i got it. bad query in server side because im linking tables automaticly ... now i have [object Object] [object Object] [object Object] [object Object] [object Object] ... probably this one will be interesting for you
  • Your aaData is an array of arrays of objects. You want to remove the inner array and just have an array of objects.
  • okey .. i removed the inner array
    now the error is "DataTables warning (table id = 'table_rabotni_mesta'): Requested unknown parameter '0' from the data source for row 0".
    am i a total mess :D
  • You need to tell DataTables which object property should be used for each column: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
  • thanks a lot ... :) its WORKING :D
    now im trying to find the topic for "sorting date in DD.MM.YYYY format
    any idea allan ? :)
  • allan thanks
    right now im reading this http://datatables.net/forums/discussion/8551/tabletools-not-working/p1 because i have the same problem. any ideas ?
  • Yes - set the SWF path. If you are a 404 error, you need to change to path to fix the error.
  • i dont have 404 error
  • In that case we'd need a link to see what the problem is.
  • the same as the one posted before table_view.php
  • 5 404 errors:


    jquery-ColReorder.js Failed to load resource: the server responded with a status of 404 (Not Found)
    jquery-KeyTable.js Failed to load resource: the server responded with a status of 404 (Not Found)
    jquery-TableTools.js Failed to load resource: the server responded with a status of 404 (Not Found)
    jquery-ColVis.js Failed to load resource: the server responded with a status of 404 (Not Found)
    jquery-ZeroClipboard.js Failed to load resource: the server responded with a status of 404 (Not Found)
  • the files are there .. otherwise i will not be able to use the other functions
  • GET jquery.js 304 Not Modified
    GET jquery-ui.js 304 Not Modified
    GET jquery-tools.js 304 Not Modified
    GET jquery-dataTables.js 304 Not Modified
    GET jquery-ColReorder.js 304 Not Modified
    GET jquery-ColVis.js 304 Not Modified
    GET jquery-KeyTable.js 304 Not Modified
    GET jquery-TableTools.js 304 Not Modified
    GET jquery-ZeroClipboard.js 304 Not Modified
    if there is na 404 error for all those .js i wont be able to use them ... but
    i can use the rest of the "extras"
    only the keytable ... not working
  • Hello

    Firstly, can I add my compliments to the mass of praise you've deservedly had for this plug-in. I have used it in many applications, especially in CRUD-style admin applications, and it's excellent.

    But now I have this same error: "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.", but I only have in IE8. I developed and tested using Chrome and Firefox and have only stared checking IE8 now everything works ok. So my app works fine in Chrome, Safari and Firefox but not in IE8. The JSON goes through lint without any error.

    How do I debug this, given that I can't reproduce the error in Firefox?
  • If it is IE only then very likely you have a trailing comma.

    If you could give us a link, that would be helpful.

    Allan
  • Thanks Allan. There's security on this app at the moment but I have made a copy so you can look at it. I have sent you the URL by PM rather than put it here.

    I thought I'd solved it last night when I noticed that IE9 wasn't accepting the JSON as JSON and was putting up a 'Save As' box instead. I solved this by changing the headers from:

    header('Content-type: application/json');

    to:

    header('Content-Type: text/plain');
    header('X-Content-Type-Options: nosniff');

    That kept IE8 happy but didn't stop it working in Firefox or Chrome.

    However, still the same error.
  • By the way, I did look for trailing commas but I'm pretty confident I don't have any. JSLint reports extra trailing commas.
  • Help?! Having the same problem on my Cart66 Professional. "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error."

    I don't know what I'm doing, so basic level instructions would be really helpful. I've submitted a support ticket but there seems to be no help. The problem is prevent cart66 from working. When we click on the button to add to cart it says "readyState:4 Status: 200" Thank you!

    http://the-human-solution.org/take-action/membership/
  • Where have you submitted a ticket? I don't have a record of anything.

    I also don't actually see how to reproduce the error. I click the add to cart button and get he readyState alert, but nothing about JSON formatting error.

    Needless to say, the JSON formatter error is exactly what it says on the tin - invalid JSON.

    Allan
  • i am using firebug (first time) to identify the json error, but i can't find the json tab. Could anyone help me, please?
    Jane
  • Just for your information: Few hours ago I just upgrade to php 5.5 from php 5.4.6: DataTables not working anymore... Got the same error message "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.".
    This message out only for the ServerSide example (I mean mySQL queries with "server_processing.php")...
    So, I do believe there is a bug somewhere as "the stuff was working before the upgrade".
    MacOS 10.8.3, Apache/2.2.22 (Unix) PHP/5.5.0 mod_jk/1.2.37 DAV/2 mod_ssl/2.2.22 OpenSSL/0.9.8x mod_perl/2.0.5 Perl/v5.12.4 - Server type: MySQL
    Server version: 5.5.28 - MySQL Community Server (GPL)

    edit: The tables used are installed from the "data.sql" file coming with the package...
    edit(2): same problem with FireFox on the same machine...
  • What is the error in the Ajax return from the server? It isn't valid JSON, so it is likely to be an error message stating what the problem is.

    Allan
  • ... and the error message is: "TypeError: 'undefined' is not an object (evaluating 'oColumn.asSorting')" at line 6705 (jquery.dataTables.js:6705)
  • That's the Javascript error. What is the error coming back from the server in the Ajax request. Please use the DataTables debugger or give us a link and we might be able to help more.

    Allan
This discussion has been closed.
All Discussions