Ajax Data Source
Ajax Data Source
Hi,
I have written a web service in c# that I want to use as an Ajax Data Source. However I think the format that the web service returns is causing a problem.
Here is what is returned from the webservice:
[code]
<?xml version="1.0" encoding="utf-8" ?>
[[["Col1","System.String","row1 - column1","Col2","System.String","row1 - column2","Col3","System.String","row1 - column3","Col4","System.String","row1 - column4","Col5","System.String","row1 - column5","Col6","System.String","row1 - column6"],["Col1","System.String","row2 - column1","Col2","System.String","row2 - column2","Col3","System.String","row2- column3","Col4","System.String","row2 - column4","Col5","System.String","row2 - column5","Col6","System.String","row2 - column6"],["Col1","System.String","row3 - column1","Col2","System.String","row3 - column2","Col3","System.String","row3 - column3","Col4","System.String","row3 - column4","Col5","System.String","row3 - column5","Col6","System.String","row3 - column6"],["Col1","System.String","row4 - column1","Col2","System.String","row4 - column2","Col3","System.String","row4 - column3","Col4","System.String","row4 - column4","Col5","System.String","row4 - column5","Col6","System.String","row4 - column6"],["Col1","System.String","row5 - column1","Col2","System.String","row5 - column2","Col3","System.String","row5 - column3","Col4","System.String","row5 - column4","Col5","System.String","row5 - column5","Col6","System.String","row5 - column6"]]]
[/code]
Here is how i'm refering to it in code:
[code]
$(document).ready(function () {
oTable = $('.myDataTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bRetrieve": true,
"sAjaxSource": 'http://123.45.678.901/MyWebService/service.asmx/TestJson'
});
});
[/code]
Would I be correct in saying that the fact that the '<?xml version="1.0" encoding="utf-8" ?>
' coming through first is causing me the problem?
If so, how can you ever hope to use the DataTables PlugIn for dynamic data?
Hope you can help,
Gray
I have written a web service in c# that I want to use as an Ajax Data Source. However I think the format that the web service returns is causing a problem.
Here is what is returned from the webservice:
[code]
<?xml version="1.0" encoding="utf-8" ?>
[[["Col1","System.String","row1 - column1","Col2","System.String","row1 - column2","Col3","System.String","row1 - column3","Col4","System.String","row1 - column4","Col5","System.String","row1 - column5","Col6","System.String","row1 - column6"],["Col1","System.String","row2 - column1","Col2","System.String","row2 - column2","Col3","System.String","row2- column3","Col4","System.String","row2 - column4","Col5","System.String","row2 - column5","Col6","System.String","row2 - column6"],["Col1","System.String","row3 - column1","Col2","System.String","row3 - column2","Col3","System.String","row3 - column3","Col4","System.String","row3 - column4","Col5","System.String","row3 - column5","Col6","System.String","row3 - column6"],["Col1","System.String","row4 - column1","Col2","System.String","row4 - column2","Col3","System.String","row4 - column3","Col4","System.String","row4 - column4","Col5","System.String","row4 - column5","Col6","System.String","row4 - column6"],["Col1","System.String","row5 - column1","Col2","System.String","row5 - column2","Col3","System.String","row5 - column3","Col4","System.String","row5 - column4","Col5","System.String","row5 - column5","Col6","System.String","row5 - column6"]]]
[/code]
Here is how i'm refering to it in code:
[code]
$(document).ready(function () {
oTable = $('.myDataTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bRetrieve": true,
"sAjaxSource": 'http://123.45.678.901/MyWebService/service.asmx/TestJson'
});
});
[/code]
Would I be correct in saying that the fact that the '<?xml version="1.0" encoding="utf-8" ?>
' coming through first is causing me the problem?
If so, how can you ever hope to use the DataTables PlugIn for dynamic data?
Hope you can help,
Gray
This discussion has been closed.
Replies
http://stackoverflow.com/questions/288850/how-to-return-json-from-a-2-0-asmx-web-service
TLDR; version:
Add the [ScriptService] attribute to your webservice method
Sorry fella, this didn't work. I've read the whole article and although I can get the Web Service to return just the Json. I can't get the dataTable to load the results.
What am I doing wrong?
Allan
http://datatables.net/usage/options#sAjaxDataProp
http://datatables.net/release-datatables/examples/ajax/objects.html
Something like:
[code]
return new { aaData = YourIEnumerableOfData };
[/code]
Not strictly true, with the sAjaxDataProp option that you noted you can change the property that DataTables looks for - although you are quite correct in that aaData is the default value :-)
Allan