Using fnServerData to get JSON from an asmx web service

Using fnServerData to get JSON from an asmx web service

timwilsontimwilson Posts: 7Questions: 0Answers: 0
edited October 2012 in DataTables 1.9
I am having trouble getting the fnServerData to poplulate the DataTable. My web service is called fine and returning data that I can access, however the DataTable constantly says "Processing"

I have it working fine with this code which gets the returned JSON from the web service before calling the dataTable plugin, however I need to be able to use the ServerSide processing as well for large datasets which I am assuming will not work with this method for obvious reasons.

Working code:

[code]
$.ajax({
type: "POST",
url: "http://localhost:52350/Webservice/AllReports.asmx/GetAllReports",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (json) {
//alert(json.d);
//alert(json.d[0].SDRRID);
//alert(json.d[0].ReportNumber);
$('#example').dataTable({
"bProcessing": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aaData": json.d,
"aoColumns": [
{ "mDataProp": "SDRRID" },
{ "mDataProp": "ReportNumber" }
]
});
}
});
[/code]

Non-working code:

[code]
$('#example').dataTable({
"bProcessing": true,
// "bServerSide": true,
"sAjaxSource": 'http://localhost:52350/Webservice/AllReports.asmx/GetAllReports',
"aoColumns": [
{ "mDataProp": "SDRRID" },
{ "mDataProp": "ReportNumber" }
],
"fnServerData": function (sSource, aoData, fnCallback, oSettings) {
oSettings.jqXHR = $.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "POST",
"url": sSource,
"data": aoData,
"success": function (json) {
// alert(json.d);
// alert(json.d[0].SDRRID);
// alert(json.d[0].ReportNumber);
fnCallback(json.d);
}
});
}
});
[/code]

If I uncomment my alerts I get actual data so I know the web service is being called and returned correctly. I do have to deal with .d from the asmx web service, but it seems to work fine in the first example so I am not sure why it won't work fine in the second example.

Thanks!

Tim

Replies

  • timwilsontimwilson Posts: 7Questions: 0Answers: 0
    edited October 2012
    Wouldn't you know, shortly after posting this I found the answer in a post just before mine...... after hours of searching!

    [code]sAjaxDataProp: ""[/code]

    Based on Allan's comment a few days ago here:
    http://datatables.net/forums/discussion/comment/40777#Comment_40777

    [quote]Ah - its because you are just returning an array, rather than the aaData parameter in an object. Simply set sAjaxDataProp to be an empty string and that should do it - i.e.:

    sAjaxDataProp: ""

    in the DataTables initialisation.

    Allan[/quote]
  • allanallan Posts: 63,394Questions: 1Answers: 10,451 Site admin
    Heh - its always the way :-). Good to hear you got this sorted out. I'll see how I can make this more obvious in the documentation refresh I'm working on.

    Allan
This discussion has been closed.