Ajax Data Source

Ajax Data Source

graygray Posts: 5Questions: 0Answers: 0
edited July 2012 in General
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

Replies

  • SconesScones Posts: 6Questions: 0Answers: 0
    edited July 2012
    This will probably explain your problem:

    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
  • graygray Posts: 5Questions: 0Answers: 0
    Scones,

    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?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    What does the JSON look like? Have you read this blog post: http://datatables.net/blog/Extended_data_source_options_with_DataTables ?

    Allan
  • SconesScones Posts: 6Questions: 0Answers: 0
    edited July 2012
    The Json must be kept in a variable named "aaData" for datatables to pick it up.

    http://datatables.net/usage/options#sAjaxDataProp

    http://datatables.net/release-datatables/examples/ajax/objects.html

    Something like:

    [code]
    return new { aaData = YourIEnumerableOfData };
    [/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > The Json must be kept in a variable named "aaData" for datatables to pick it up

    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
This discussion has been closed.