sAjaxSource does not show any data

sAjaxSource does not show any data

hsajjadhsajjad Posts: 28Questions: 0Answers: 0
edited November 2013 in General
Hi,

I'm new to data tables and currently trying to evaluate (PoC) it for large data sets.

I notice that sAjaxSource works OK when I have my JSON data sourced from a local file however, it does not display / render anything if configured to pull directly from a restful web service.

This works:
"bProcessing": true,
"sAjaxSource": "my-copied-json-data.txt",
"sAjaxDataProp": "",

This doesn't work:
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost:9001/ismb/api/getMessage",
"sAjaxDataProp": "",

I can see the webservice is getting hit and returning data (from logs), although I don't see this being displayed inside the HTTP Response object on Firebug.I have also tried fnServerData param but with no gain!

The above webservice will return JSON that's validated OK on JSONLint, and looks like:
[
{
"busId": "1",
"domainId": x,
...
},
{
"busId": "2",
"domainId": y,
...
}
]

Appreciate help! Thanks

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    We'd need a link to a test case please. What does the JSON data look like for example.

    Allan
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Hi Allan

    The test case submission service is unavailable, hence describing it here.
    Let me know if need more info.

    [code]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





    Bus Test


    @import "media/css/demo_page.css";
    @import "media/css/demo_table.css";







    $(document).ready(function() {
    var oTable = $('#table_id').dataTable( {
    "bProcessing": true,
    //"bServerSide": true,
    //"sAjaxSource": "http://localhost:9001/ismb/api/getMessage",
    "sAjaxSource": "bus-poc-data.txt",
    "sAjaxDataProp": "",
    "aoColumns": [
    { "mData": "busId" },
    { "mData": "sourceSystem" },
    { "mData": "receiveTime" },
    { "mData": "validationStatus" },
    { "mData": "messageId" }
    ]
    } );
    } );












    Bus Id
    Message Id
    Source System
    Received
    Validation Status







    Bus Id
    Message Id
    Source System
    Received
    Validation Status








    [/code]


    Sample "bus-poc-data.txt" content:
    [code]
    [
    {
    "busId": "N02P02-f0e6f22b-3a0c-48b0-bd9a-df9b94c9714f",
    "domainId": 1,
    "sourceSystem": "TEST-NY-EDG",
    "receiveTime": 1382453631320,
    "validationStatus": "V",
    "messageId": "123-default",
    "messageType": null,
    "routingStatus": "R",
    "businessIds": null,
    "recipients": null
    },
    {
    "busId": "N02P02-efb99ce0-5ede-45c5-b5e6-64e1fc9cad25",
    "domainId": 1,
    "sourceSystem": "TEST-NY-EDG",
    "receiveTime": 1382453631320,
    "validationStatus": "V",
    "messageId": "123-default",
    "messageType": null,
    "routingStatus": "R",
    "businessIds": null,
    "recipients": null
    },
    {
    "busId": "N02P02-1e1bfcbd-a42f-484a-826d-35a0a9aeafcd",
    "domainId": 1,
    "sourceSystem": "TEST-NY-EDG",
    "receiveTime": 1382453631320,
    "validationStatus": "V",
    "messageId": "123-default",
    "messageType": null,
    "routingStatus": "R",
    "businessIds": null,
    "recipients": null
    }
    ]
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Odd - that really does look like it should work. You can't link us to the page you are working on?

    Allan
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Sorry no, this is behind a corp firewall.

    Is there a way to trace things i.e. enable debug? Firebug doest not flag any error, and using that I can see the response has no JSON in it.

    Thanks
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Think this is same as: http://datatables.net/forums/discussion/comment/40611
    .. and to do with cross domain scripting issues.
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Allan,

    One enhancement: the jsonp example here: http://www.datatables.net/beta/1.9/examples/server_side/jsonp.html
    should ideally be configured to access cross-domain data i.e. from a public domain such as wikipedia, dbpedia or a host of other socio/tech services out there, instead! There's slight overhead, external dependency created, but on the net I think there's more value to users like me.
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Things are a step closer by moving and deploying my HTML table (with datatable's javascript) to the server with restful webservice running.

    I now see a potential bug in code (lines 2037-2038 in jquery.dataTables.js, _fnAjaxUpdateDraw, with error on line 2038 complaining 'aData is undefined'. Two lines copied below - don't understand the first with declaration on - syntactically seems incorrect?

    var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
    for ( var i=0, iLen=aData.length ; i
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Replacing line 2037 from:

    var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );

    to:
    (oSettings.sAjaxDataProp !== "") ?
    _fnGetObjectDataFn( oSettings.sAjaxDataProp )(json) : json;

    works!
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hmmm - there is something odd going on there. It looks very much like it should work - sAjaxDataProp as an empty string (assuming you are using 1.9.4?) will read in the array.

    Allan
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Yep it's the latest 1.9.4 version. Same config (sAjaxDataProp = "") works BAU when JSON data is sourced from file..
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    How were you feeding it the data if it wasn't coming via Ajax? aaData expects the data source array - not any other object.

    Allan
  • hsajjadhsajjad Posts: 28Questions: 0Answers: 0
    Yes still coming via Ajax, but directly sourced from a file - no serverside (bServerSide = false). In this scenario the above problem line (#2037) doesn't get hit. If the bServerSide = true, then I see the same issue reproduced on ajax reading a local file.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Can you show me the code please?
This discussion has been closed.