不能做跨域Ajax调用 [英] Cant make a crossdomain Ajax call
问题描述
$(document).ready(function(){
$ .ajax({
url: http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2 ,
类型:GET,
success:function(msg){
console.log(msg);
}
});
});
我收到此错误XMLHttpRequest无法加载 http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2
如何我做交叉域ajax调用从api获取xml?
不能进行跨域调用来获取XML。您只能接收数据跨域的选择是 JSON-P
。
限制直接访问外部域(ajax / iframes), json-p
使用 c $ c>解决此问题。
请查看 http://api.jquery.com/jQuery.getJSON/ 。 JSON-P
也包括在内。
编辑
$ b
http:/ /code.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_json.html
为您量身打造!
$(document).ready(function(){ $.ajax({ url: "http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2", type: "GET", success: function(msg){ console.log(msg); } }); });
i get this error "XMLHttpRequest cannot load http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2"
How can i make crossdomain ajax calls to get the xml from the api?
You cannot make a crossdomain call to to get XML. Your only choice to receive data crossdomain is JSON-P
.
The same origin policy
restricts direct access to a foreign domain (ajax/iframes), json-p
uses dynamic script tag insertion
to workaround this issue.
Have a look at http://api.jquery.com/jQuery.getJSON/. JSON-P
is also covered there.
edit
http://code.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_json.html
Made for you!
这篇关于不能做跨域Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!