_fnAjaxUpdateDraw crashes on "var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );"
_fnAjaxUpdateDraw crashes on "var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );"
yasvintus
Posts: 7Questions: 0Answers: 0
Hello,
I am sure this is something obvious, but I can't figure out what's going on. I am using a server side ajax datasource. If I have the server side method that returns some jsonp.
The datatable is set up like this (per http://datatables.net/release-datatables/examples/server_side/jsonp.html)
[code]
oTable = $('#example').dataTable({
"bServerSide": true,
"sAjaxSource": url,
"fnServerData": function (sUrl, aoData, fnCallback) {
$.ajax({
"url": sUrl,
"data": aoData,
"success": fnCallback,
"dataType": "json",
"cache": false
});
}
[/code]
When I load the page, the datatables scrip crashes because the following line results in an undefined aData object
[code]
var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
[/code]
(line 2037 of jquery.dataTables.js v. 1.9.4)
When the crash happens the value of the json parameter in the debugger is:
{"sEcho":1,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[["Vasya","Doer","1","1/1/0001"],["Petya","Boss","2","1/1/0001"]]}
Seems valid, right?
What am I doing wrong?
Thank you!
Daniel
I am sure this is something obvious, but I can't figure out what's going on. I am using a server side ajax datasource. If I have the server side method that returns some jsonp.
The datatable is set up like this (per http://datatables.net/release-datatables/examples/server_side/jsonp.html)
[code]
oTable = $('#example').dataTable({
"bServerSide": true,
"sAjaxSource": url,
"fnServerData": function (sUrl, aoData, fnCallback) {
$.ajax({
"url": sUrl,
"data": aoData,
"success": fnCallback,
"dataType": "json",
"cache": false
});
}
[/code]
When I load the page, the datatables scrip crashes because the following line results in an undefined aData object
[code]
var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
[/code]
(line 2037 of jquery.dataTables.js v. 1.9.4)
When the crash happens the value of the json parameter in the debugger is:
{"sEcho":1,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[["Vasya","Doer","1","1/1/0001"],["Petya","Boss","2","1/1/0001"]]}
Seems valid, right?
What am I doing wrong?
Thank you!
Daniel
This discussion has been closed.
Replies
Allan
make sure you're returning valid JSONP
Allan -- you can see the page here: http://grq.freink.net/wcf/default.html Sorry, I should've referenced this link in the first place.
Fbas -- yes, the jsonp response looks valid in Fiddler (see below), but once it gets into the js function where the crash happens it loses the parentheses.
jQuery18202853988258048709_1373588742548("{\"sEcho\":1,\"iTotalRecords\":2,\"iTotalDisplayRecords\":2,\"aaData\":[[\"Vasya\",\"Doer\",\"1\",\"1\/1\/0001\"],[\"Petya\",\"Boss\",\"2\",\"1\/1\/0001\"]]}");
i.e. currently there is:
[code]
_("{\"sEcho\":1,\"iTotalRecords\":2, ...
[/code]
You want to return JSON like:
[code]
_({"sEcho":1,"iTotalRecords":2, ...
[/code]
So a little update to your script is needed to do that.
Allan
You mean the server-side script, right? I actually started by returning a Stream object from the server and you're right -- the datatable bound well, however I couldn't get the server to wrap the json in the jsonP padding. It seemed that wcf binding will only spit out jsonp when I am returning a string.
So no way to make datatables work with a string?
Thanks again!
It expects an object. You could use something like:
[code]
"success": function ( text ) {
fnCallback( $.parseJSON( test ) );
}
[/code]
Allan
http://social.msdn.microsoft.com/Forums/vstudio/en-US/b490fb20-6418-469d-8957-4ccf87fba0ff/endpoint-encoding