Jquery DataTable fnServerData Error

Jquery DataTable fnServerData Error

lorengphdlorengphd Posts: 3Questions: 0Answers: 0
edited May 2012 in General
I posted this question on stackoverflow.com as well about a day ago. No responses.
http://stackoverflow.com/questions/10544443/jquery-datatable-fnserverdata-error

I am attempting to load my jQuery Datatable via Ajax from an asp.net web service (.asmx) file.

I am using the following jQuery:

[code]
$("#taskTable").dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajaxPages/getTheTasks.asmx/getAllTasks",
"fnServerData": function (sSource, aoData, fnCallback) {
alert("test");
aoData.push({ "name": "id", "value": ProjectID });
$.getJSON(sSource, aoData, function (json) {
fnCallback(json);
});
}
});
[/code]

I have been debugging with firebug. I can stop on each of the lines all the way down to "fnserverData". Once I hit that line, I can't step into the function. The alert never triggers. I never even get to send a request to the web service. It just skips over. I've rewritten this code several times and based it off of several different examples.

This code here is nearly verbatim from the datatables websites, which does work. (The datatables website example uses a PHP source. I even copied that source and tried to use that through the sAjaxSource but it still didn't step into the fnServerData.

In case anyone asks, my web service returns a string (serialized json). I can't imagine the web service being an issue here seeing as though the request never even gets sent.

If I put a break point on the $.getJSON line, it never hits. My debugger never outputs an error.

Thanks anyone for checking this out!

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    I've just put your example into the 'live' site to test it and it seems to work as expected to me: http://live.datatables.net/ovufev/edit#javascript,html . The alert is thrown up and then the JSON is returned and populated in the table. So I think to be able to offer any further suggestions we'd need to see your example not working.

    One thing I would say is that I strongly suspect it will be a JSON error - your server likely isn't returning valid JSON and since there is no 'error' handling function it just disappears. I'd suggest using fnServerParams rather than fnServerData for just adding an extra parameter to the parameter list. Then we can use the debugger ( http://debug.datatables.net ) to get more of an idea of what might be going wrong.

    Allan
  • lorengphdlorengphd Posts: 3Questions: 0Answers: 0
    Problem solved. It was really dumb and just glaring at me. I didn't have a table on the page with the id of "taskTable". Before I took on the Ajax source feature of the datatable I was loading the table from a different page. I forgot to bring it forward.

    Thanks for the consideration, Allan.
This discussion has been closed.