如何使用jQuery JSONP进行跨域Ajax调用 [英] How to make cross domain ajax call using jQuery JSONP

查看:102
本文介绍了如何使用jQuery JSONP进行跨域Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该更改以下代码以使用jsonp加载XML跨域.

What should I Change the below code to load XML cross domain using jsonp..

$.ajax({
    type: "GET",
    url: "http://www.w3schools.com/xml/note.xml",
    dataType: "xml",
    success: function(xml) {
        alert('Hi');
    }
});

希望我的问题得到解决.

Hope my problem is resolved.

推荐答案

据我所知,您不能(直接)使用JSONP加载XML数据.

As far as I know you can't (directly) load XML data using JSONP.

使用JSONP的跨站点AJAX依赖于将所需的对象包装在动态创建的<script>标记内执行的Javascript函数调用中,并且没有使用XML进行此操作的机制.

Cross-site AJAX with JSONP relies on wrapping the required object inside a Javascript function call that's executed inside a dynamically created <script> tag, and there's no mechanism for doing that with XML.

甚至JSONP都要求远程服务器执行JSON包装-输出JSON数据的CGI脚本并不能自动支持JSONP.

Even JSONP requires that the remote server perform the JSON wrapping - a CGI script outputing JSON data doesn't automatically support JSONP out of the box.

如果您的数据实际上是位于标准FTP服务器上的纯XML文件,那么这显然是不可能的.

That's clearly going to be impossible if your data is actually plain XML files sat on an standard FTP server.

这篇关于如何使用jQuery JSONP进行跨域Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆