不能让一个跨域Ajax调用能让、Ajax

由网友(不交电费瞎发啥光)分享简介:$(document).ready(function(){$.ajax({url: "http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2",type: "GET",success: function(msg){console.log(msg);}});...
$(document).ready(function(){
    $.ajax({
        url: "http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2",
        type: "GET",
        success: function(msg){
            console.log(msg);
        }
    });
});

我得到这个错误XMLHtt prequest无法加载 http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2

我怎样才能让跨域Ajax调用从API获取XML?

How can i make crossdomain ajax calls to get the xml from the api?

推荐答案

您无法进行跨域调用来获得XML。你唯一的选择接收数据跨域是 JSON-P

You cannot make a crossdomain call to to get XML. Your only choice to receive data crossdomain is JSON-P.

同源策略限制直接访问外部域(AJAX /内置页框), 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.

看一看 http://api.jquery.com/jQuery.getJSON/ 。 JSON-P 也包括在那里。

Have a look at http://api.jquery.com/jQuery.getJSON/. JSON-P is also covered there.

修改

http://$c$c.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_json.html

为你做的!

阅读全文

相关推荐

最新文章