Reputation: 157
I am trying to write a HTML5 mobile application and use jQuery to get a json from the url http://cin.ufpe.br/~rvcam/favours.json I tried using
var url='http://cin.ufpe.br/~rvcam/favours.json';
$.getJSON(url, function(data, status)
{
console.log(data);
console.log(status);
});
but nothing shows up on the console. I don't see what I am doing wrong.
[EDIT] I learned from another post that I can't normally retrieve information from another server. But this server in particular (cin.ufpe.br/~rvcam) is mine. Can I use PHP or some other method to allow my application to retrieve the data?
Upvotes: 0
Views: 53
Reputation: 646
The URL doesn't return valid json. It returns some JavaScript that attempts to execute a function called "foo" and passes the object as an argument. This is commonly called "jsonp". It is a method of achieving cross domain ajax calls
Upvotes: 5
Reputation: 1604
Your http://cin.ufpe.br/~rvcam/favours.json
file isn't valid json. The valid json is wrapped in foo()
. Remove the foo()
from that file and it will work.
Upvotes: 2