Brandon
Brandon

Reputation: 309

Why isn't $.getjsonworking?

I'm trying to get remote json data however I'm unable to. My temporary solution was to use http://whateverorigin.org/ but it's no longer working for me. So now I'm back to trying to figure out why I'm unable to get the remote json the normal way with $.getJSON. Here's the code:

$.getJSON("http://www.catholic.com/api-radio/6431?callback=?", function(result){
//response data are now in the result variable
alert(result);
});

Here's the jsfiddle:

http://jsfiddle.net/5ZK9A/

Upvotes: 2

Views: 44

Answers (1)

Quentin
Quentin

Reputation: 943217

You are making a request for JSONP (which is a JavaScript program with one function call). The server is responding with JSON (which it claims is HTML).

JSON (by itself) usually (and in this case) isn't valid JavaScript, so the attempt to run the program errors. You would have seen this if you had looked at your JavaScript error console.

You'll need to persuade the service to supply a JSONP response or use some other means to circumvent the same origin policy.

Upvotes: 5

Related Questions