Using fnServerData to get JSON from an asmx web service
Using fnServerData to get JSON from an asmx web service
timwilson
Posts: 7Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
[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]
Allan