Cant make a crossdomain Ajax call(无法进行跨域 Ajax 调用)
问题描述
$(document).ready(function(){$.ajax({网址:http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2",类型:获取",成功:功能(味精){控制台日志(味精);}});});
$(document).ready(function(){ $.ajax({ url: "http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2", type: "GET", success: function(msg){ console.log(msg); } }); });
我收到此错误XMLHttpRequest 无法加载 http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2"
i get this error "XMLHttpRequest cannot load 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/iframes),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://code.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_json.html
为你量身定做!
这篇关于无法进行跨域 Ajax 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法进行跨域 Ajax 调用


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01