cross domain ajax works but there's no data displayed in my table : (
cross domain ajax works but there's no data displayed in my table : (
hsajjad
Posts: 28Questions: 0Answers: 0
https://datatables.net/release-datatables/examples/server_side/jsonp.html
The above setting works (below) - confirmed on the firebug, the JSON data is retrieved, but my issue is it's not shown on the table!!
Any clues why??
[code]
$(document).ready(function() {
$('#table_id').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost:9001/api/gui/messages",
"fnServerData": function( sUrl, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"url": sUrl,
"data": aoData,
"success": fnCallback,
"dataType": "jsonp",
"cache": false
} );
},
"bDeferRender": true,
"aoColumns": [
{ "mData": "busId", "bSortable": false },
{ "mData": "sourceSystem", "bSortable": false },
{ "mData": "receiveTime", "bSortable": false },
...
],
"sDom": "rtp",
"sPaginationType": "full_numbers",
"iDisplayLength": 20
} );
} );
[/code]
Just to verify things, if source data locally i.e. replace:
"sAjaxSource": "http://localhost:9001/api/gui/messages",
"fnServerData" ...
with something like:
"sAjaxSource": "resources/data.txt",
then all works!
I'm using DataTables 1.9.4
Thanks!
The above setting works (below) - confirmed on the firebug, the JSON data is retrieved, but my issue is it's not shown on the table!!
Any clues why??
[code]
$(document).ready(function() {
$('#table_id').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost:9001/api/gui/messages",
"fnServerData": function( sUrl, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"url": sUrl,
"data": aoData,
"success": fnCallback,
"dataType": "jsonp",
"cache": false
} );
},
"bDeferRender": true,
"aoColumns": [
{ "mData": "busId", "bSortable": false },
{ "mData": "sourceSystem", "bSortable": false },
{ "mData": "receiveTime", "bSortable": false },
...
],
"sDom": "rtp",
"sPaginationType": "full_numbers",
"iDisplayLength": 20
} );
} );
[/code]
Just to verify things, if source data locally i.e. replace:
"sAjaxSource": "http://localhost:9001/api/gui/messages",
"fnServerData" ...
with something like:
"sAjaxSource": "resources/data.txt",
then all works!
I'm using DataTables 1.9.4
Thanks!
This discussion has been closed.
Replies
Allan
I just noticed, your example does not load any data when run locally on my machine - using Firefox 4 or IE 8. Both browsers display 'Loading data from server' and remain at it!
Example:
file:///C:/DataTables-1.9.4/examples/server_side/jsonp.html
Is this supposed to work..?
Thanks
That's not going to do much unless you replace "file:" with "localhost:" and fix the path appropriately..
As tangerine says, this won't work. Browsers have built in security to stop exactly this. It would ba a _massive_ security hole if any site could just randomly load files from your hard disk!
Thee is no way around that. You need a web server.
Allan
Moved the server part from remote to localhost (within same webapp) as:
[code]
"sAjaxSource": "query.do?id=777",
[/code]
and removed 'fnServerData' part. Still no fun, I can see the JSON being fetched successfully (as before) but no data display on the dtable.
[quote]
{
"aaData":[{"busId":"777","domainId":1,"sourceSystem":"TEST-GW","receiveTime":1386931764000,"validationStatus":"V","messageId":"456-yy","messageType":"tradeCreate","routingStatus":"R","businessIds":[{"scheme":"http://test-gw.jpm.com","value":"123456","version":""}],"recipients":[{"systemId":"NAPOLI-TS","sentTime":1386931764000,"deliveryStatus":"F","deliveryFailureReason":null},{"systemId":"TEST-GW","sentTime":1386931764000,"deliveryStatus":"D","deliveryFailureReason":null}]}],
"iTotalRecords":1,
"iTotalDisplayRecords":1,
"sEcho":0
}
[/quote]
All is hunky dori if you point sAjaxSource to a text file with this JSON data.
Any help is highly appreciated.
For my app, I do deploy it on Tomcat though using localhost. And I can see on Firebug the ajax is getting executed and fetching data as expected, it's just not displayed, as per my last comment.