DataTables warning: JSON data from server could not be parsed.
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:
[code]
One
Two
Three
Four
Five
Six
Seven
[/code]
Javascript:
[code]
$('#test_table').dataTable({
"sAjaxSource" : 'dt_ajax.txt'
});
[/code]
JSON Data:
[code]
{"aaData": [
[
"",
"3S",
"38",
"09",
"300000",
"500000",
"Test data"
],
[
"",
"5I",
"34",
"12",
"500000",
"1000000",
"aaaaa"
],
[
"",
"Jumbo",
"9",
"8",
"888888",
"8888888",
"testtt"
]
]}
[/code]
Thanks in advance! P.S. The data works fine when input directly. Only "sAjaxSource" is getting this error.
"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:
[code]
One
Two
Three
Four
Five
Six
Seven
[/code]
Javascript:
[code]
$('#test_table').dataTable({
"sAjaxSource" : 'dt_ajax.txt'
});
[/code]
JSON Data:
[code]
{"aaData": [
[
"",
"3S",
"38",
"09",
"300000",
"500000",
"Test data"
],
[
"",
"5I",
"34",
"12",
"500000",
"1000000",
"aaaaa"
],
[
"",
"Jumbo",
"9",
"8",
"888888",
"8888888",
"testtt"
]
]}
[/code]
Thanks in advance! P.S. The data works fine when input directly. Only "sAjaxSource" is getting this error.
This discussion has been closed.
Replies
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
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
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.
Allan
Allan
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
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
[code]
{
"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"
]
]
}
[/code]
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.
Just ignore my question above. the problem solved, already. Thanks!
"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?
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
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": "auctor.vitae@Aeneanegestashendrerit.ca",
"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": "netus@Cras.org",
"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": ""
}
}
]
}
Allan
Any help please????
Allan
[code]
$.fn.dataTableExt.sErrMode = 'throw';
[/code]
Allan
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
$(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" } );
} } ); } );
here is the HTML:
Зареждане на информацията от сървъра
WHERE DID I GET WRONG???
WHERE DD I GET WRONG
[code]
ORDER BY p.firm_name as firm_name asc<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">Error on expert-2002.combody { 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; }FOUND ERROR !!!Bad query extentions: 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, 10More information about this may be available in the expert-2002.com server error log.©Copyright 2002-2012 eXpert-2002.com | дизайн и хостинг еКсперт-2002
[/code]
Allan
server file is http://expert-2002.com/multisys/support/table_server.php
Allan
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
Allan
now im trying to find the topic for "sorting date in DD.MM.YYYY format
any idea allan ? :)