无法进行跨域 Ajax 调用
$(文档).ready(函数(){ $.ajax({ 网址:“http://gdata.youtube.com/feeds /api/users/zdf/playlists?v=2", 类型:“获取”, 成功:函数(消息){ 控制台.log(消息); } }); });
我收到此错误“XMLHttpRequest 无法加载 http://gdata. youtube.com/feeds/api/users/zdf/playlists?v=2"
我如何进行跨域 ajax 调用以从 api 获取 xml?
$(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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法进行跨域调用来获取 XML。您跨域接收数据的唯一选择是
JSON-P
。同源策略
限制对外部域(ajax/iframes)的直接访问,json-p
使用动态脚本标记插入
来解决此问题。查看 http://api.jquery.com/jQuery.getJSON/。其中也涵盖了
JSON-P
。编辑
http://code .google.com/intl/de-DE/apis/youtube/2.0/developers_guide_json.html
专为您打造!
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
usesdynamic 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 请求的方案 JSON-P 只是一个临时解决方法,因为它使用 script 标签来发出 HTTP 请求,这比 XMLHttpRequest 对象要差。
所提出的解决方案基于让资源源指定允许哪些域发出跨域请求,域“*”意味着任何其他网页都可以托管向该特定资源发出请求的应用程序。
您可以在 w3c 工作草案中阅读更多信息,
现代网络浏览器支持此功能。
There is an ongoing standardization process to work out a scheme to allow cross-domain ajax requests JSON-P is just a temporary workaround since it uses the script tag to make HTTP requests, which is inferior to the XMLHttpRequest object.
The proposed solution is based on letting the resource origin specify which domains that are allowed to make cross-domain requests, the domain "*" means that any other web page can host an application that makes requests to that specific resource.
You can read more in the w3c Working draft
This is supported in modern web-browsers.
尝试 $.load() 。请参阅 http://api.jquery.com/load/
try $.load() . see http://api.jquery.com/load/