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?
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/
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.