JSON format?
JSON format?
Hi, i got a php script which gives me a json string. if i echo that string and save it to a file and do
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'file'
} );
it works. but if i return that string and do
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'backend.php'
} );
it doesnt work, why? i get an error DataTables warning: JSON data from server failed to load or be parsed. This is most likely to be caused by a JSON formatting error. but tahts not possible since it works manually.
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'file'
} );
it works. but if i return that string and do
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'backend.php'
} );
it doesnt work, why? i get an error DataTables warning: JSON data from server failed to load or be parsed. This is most likely to be caused by a JSON formatting error. but tahts not possible since it works manually.
This discussion has been closed.
Replies
Below is my JSON result.
[code]
{"sEcho":1
,"iTotalRecords":11
,"iTotalDisplayRecords":10
,"aaData":[
["1","MDH","MDS - API"],["2","P2PS","P2PSClient"]
,["3","RMDS","teswt"],["4","RWDS","test"]
,["4","RWDS","test"],["4","RWDS","test"]
,["4","RWDS","test"],["4","RWDS","test"]
,["4","RWDS","test"],["4","RWDS","test"]
,["4","RWDS","test"]
]}
[/code]
I use JSONResult to return data back to the page
[code]
return Json(result, "application/json");
[/code]
The "result" is an object of below class.
[code]
public class DataTableResult
{
public int sEcho { get; set; }
public int iTotalRecords { get; set; }
public int iTotalDisplayRecords { get; set; }
public List aaData { get; set; }
}
[/code]
I don't have a clue of what I done worng. Please help!!
P.S. Sorry for my bad english
that my json:
{"aaData":[["1","qwe","123"],["2","qwe","123"],["3","qwe","123"]]}
and i use it in jquery with "sAjaxSource": "files/php/getJSON.php"
i would guess your issue is at
"sEcho":1
02.,"iTotalRecords":11
03.,"iTotalDisplayRecords":10
04.,"aaData"
im a totally newbie but i think it is sEcho OR aaData. delete the aaData. But im rly a newbie :p but maybe it helps. post the code where you use the json data.
Allan
Just change return statement into this
[code]
return Json(result, JsonRequestBehavior.AllowGet);
[/code]
I don't really know why, maybe because DataTables use request method as GET?
Anyway, thank you for replies :D
Allan