How to retrieve JSON data from a Remote server?

How to retrieve JSON data from a Remote server?

srikanthreddysrikanthreddy Posts: 7Questions: 0Answers: 0
edited June 2013 in General
Hi Everyone,

I'm trying to display Json data on my JQuery datatable. The json data is on remote server, if the json data is on my server then i'm able to fetch and display the data on my datatable but i can't able to fetch the json data from a remote server . How can i get the json data from a remote server? . Following is my sample code.

This is the URL('http://xxx.xxx.xxx:8088/test/validGetMyApplications.json'; , on a remote server ) is having my JSON object, i'm trying to hit this URL and trying to pull the json data from this URL to display this data in Jquery Datatable.
but, when i'm trying with this following code it is not hitting the URL.

Any suggestions please. Thanks.


$(document).ready(function() {
$('#myapplicationstable').dataTable();
$.ajax({
url: 'http://xxx.xxx.xxx:8088/test/validGetMyApplications.json',
async: false,
dataType: 'json',
success: function (data) {
$.each(data.applicationMainList, function(key, item) {
$('#myapplicationstable').dataTable().fnAddData( [
item.Id,
item.appLink.linkName,
item.applicationIdName.applicationName,
item.appAcronym,
item.applicationOwner.name
]
);
});
}
});

} );

Replies

  • allanallan Posts: 63,106Questions: 1Answers: 10,394 Site admin
    You probably need to use JSONP, assuming the target server supports JSONP or you can add it. If not, then you might need to use something like Yahoo Pipes or a proxy script on your own server. A google search for 'javascript cross domain ajax' will yield a lot of results.

    Allan
  • srikanthreddysrikanthreddy Posts: 7Questions: 0Answers: 0
    Hi Allan,

    Thanks a lot for your response.

    But, my remote server gives me just json object(objectData), in the format is something like this :

    {
    "objectData":
    {
    "abc": "123",
    "def": "456",
    "ghi": {
    "454": "abcdef",
    "Id": "12324"
    }
    }
    }

    it is not having any callback to it. So, is that possible to get a json object without using jsonp(because i dont have a callback from remote server). Any Suggestion please.

    Thanks,
  • allanallan Posts: 63,106Questions: 1Answers: 10,394 Site admin
    I'd suggest goggling for 'javascript cross domain ajax' as I said. Its not really a DataTables issue, more a general Javascript / security one.

    Allan
  • srikanthreddysrikanthreddy Posts: 7Questions: 0Answers: 0
    Okay, will try that. Thanks Allan.
This discussion has been closed.