如何使用jQuery JSONP进行跨域Ajax调用

编程入门 行业动态 更新时间:2024-10-11 19:22:48
本文介绍了如何使用jQuery JSONP进行跨域Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

$.ajax({ type: "GET", url: "www.w3schools/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调用

本文发布于:2023-11-28 12:42:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   jQuery   Ajax   JSONP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!