Unable to display json content fetched through http url

Unable to display json content fetched through http url

rv_nathrv_nath Posts: 7Questions: 0Answers: 0
edited August 2013 in DataTables 1.9
Hello,

I am trying to display aaData content received through a JSON into my datatables. However it just shows "processing..." message on the UI and the data never gets shown.

In firebug, I am able to see that the data has arrived at the browser. The response header is as below:

[code]
Response Headersview source
Content-Type application/json;charset=ISO-8859-1
Date Tue, 06 Aug 2013 12:40:12 GMT
Server Apache-Coyote/1.1
Transfer-Encoding chunked
X-Powered-By Servlet 2.4; JBoss-4.3.0.GA_CP02 (build: SVNTag=JBPAPP_4_3_0_GA_CP02 date=200808051050)/JBossWeb-2.0
Request Headersview source
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Host 172.16.7.248:8480
Origin null
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0

1 request
4 KB
[/code]


The code for dataTable initialization is the below one:

[code]
$("#tblData").dataTable( {
"sDom" : "<'row'<'span12'f>r>t<'row'<'span12'lp>>",
"aLengthMenu": [2,5,10, 25, 50, "None"] ,
"bProcessing" : true,
"bServerSide" : true,
"bSort" :false ,
"dataType" : "JSON",
"fnCreatedRow" : function(nRow, aData, iDataIndex) {
console.log(aData);
if (aData['status'] == "A") {
$('td:eq(2)', nRow).html("");
}
else {
$('td:eq(2)', nRow).html("");
}

},
"sAjaxSource": "http://172.16.7.248:8480/dbill/gui?action=1&type=11",
"success" : function(data) {
console.log(data);
},
"error" : function(data) {
console.log(data);
},
//"sAjaxSource": "server_processing.json",
"aoColumns": [
{ "mData": "id" },
{ "mData": "price" },
{ "mData": "status" },
{ "mData": "st-date"},
{ "mData": "end-date"},
{ "mData": "combo-plan"},
{
"mData": null,
"sDefaultContent": ' '
}

]


} );
[/code]

Notes:
1. If I use a file url instead of http, it works fine and shows all the rows from JSON. It fails with http only.
2. In spite of putting console.log in success and error functions, nothing gets shown.

Thanks in advance for your kind help.

regards,
RV

Replies

  • aaronwaaronw Posts: 89Questions: 3Answers: 4
    You may be running into cross-domain AJAX requests - http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain - short version, you can't do ajax requests to a different 'domain' than your host is in.
  • rv_nathrv_nath Posts: 7Questions: 0Answers: 0
    Hi Aaronw,
    You are right, as the original web page is coming from local file system, while the Ajax call is made to a different server. But in my case, I am getting a response 200 when checked with firebug. I don't see any actual JSON 'data' though, except the response headers that I posted in my original question. Is this because of different server?

    regards,
    RV
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Yes - the browser will block any content in the HTTP message body for security reasons. JSONP and Yahoo Pipes are options if you must make a cross domain request, although they obviously won't help with a file:// request.

    Allan
This discussion has been closed.