Reputation: 2429
I have a basic script designed to take some data from a JSON feed and return it in an alert. I can't seem to get my code working though. I am using jQuery and calling on a script hosted on a separate domain. My current code does not even display the alert even though jQuery is being loaded in properly and all the other common issues.
Does anyone have any ideas?
My code is:
$.getJSON("http://www.domain.com/api.php?q=test&callback=?",
function(data) {
alert(data.users[0].firstName);
});
Upvotes: 2
Views: 157
Reputation: 236172
If I call
http://pulse.wixiy.net/playground/search/api.php?q=wixiy&callback=?
in my browser, the response is
({"users":[ { "firstName":"Ray", "lastName":"Villalobos", "joined":2012 }, { "firstName":"John", "lastName":"Jones", "joined":2010 } ]})
which is a pure JSON string, but no valid JSONP response. For a valid JSONP response, you need a function call which invokes the JSON string object literal.
jQuery4022random242932crap311({"users":[ { "firstName":"Ray", "lastName":"Villalobos", "joined":2012 }, { "firstName":"John", "lastName":"Jones", "joined":2010 } ]});
where jQuery4022random242932crap311 is some name that jQuery generates when passing in a ?
as parameter for callback. Your server needs to read that parameter and create the above answer.
Upvotes: 2