Reputation:
Using jquery's $.ajax function, I'm not able to parse the results. For example, I used it like this
$.ajax({
url : "http://api.twitter.com/1/users/show.json?screen_name=techcrunch",
dataType : "json",
success : function(data)
{
// parse the JSON here
},
error : function()
{
alert("Failure!");
},
});
This doesn't work. Do I need a callback function?
Upvotes: 0
Views: 2931
Reputation: 15961
As metnioned, this is due to the Same Origin Policy. To get around this, you should set your datatype to jsonp
.
$.ajax({
url : "http://api.twitter.com/1/users/show.json?screen_name=techcrunch",
dataType : "jsonp",
success : function(data)
{
console.log(data);
},
error : function()
{
alert("Failure!");
},
});
Example: http://jsfiddle.net/jonathon/bpnbj/
Upvotes: 1
Reputation: 8057
You can't make an ajax call to an external url due to Same Origin Policy. You can see more info in Call external url through $.ajax in wordpres theme thread.
Upvotes: 0