Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取xml结果(跨域请求)?_Javascript_Jquery_Ajax_Xml_Json - Fatal编程技术网

Javascript 如何获取xml结果(跨域请求)?

Javascript 如何获取xml结果(跨域请求)?,javascript,jquery,ajax,xml,json,Javascript,Jquery,Ajax,Xml,Json,我需要向一个专门的网站发出请求,出于跨域原因使用jsonp来获取XML结果并处理它。 因此,基本上我这样做是为了开始: (function($) { var url = 'http://www.website.....'; $.ajax({ type: 'GET', url: url, // async: false, // contentType: "application/json", dataType: 'jsonp', }); })(jQuery); 我终于可

我需要向一个专门的网站发出请求,出于跨域原因使用jsonp来获取XML结果并处理它。 因此,基本上我这样做是为了开始:

(function($) {
var url = 'http://www.website.....';
$.ajax({
   type: 'GET',
    url: url,
   // async: false,
   // contentType: "application/json",
dataType: 'jsonp',
});
})(jQuery);
我终于可以从网站上得到答案了,我可以在firebug插件中看到,但在XML选项卡中可以看到 例如:

<Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:noNamespaceSchemaLocation="http://www.website.com">
<ResultSet id="searchResults" numResults="3" >
据我所知,jsonp是一个json对象,在我的例子中,它返回一个XML内容


我的问题是如何管理从网站返回的XML?我可以解析它并在javascript代码中使用。

您需要定义JSONPCCallback,以便修改请求的返回值

见:


尝试在ajax选项中添加回调。我认为$.ajax不会在jsonp请求中接受xml。它基本上是一个脚本请求,其中响应是一个函数调用。我认为这不会很好地评估xml。建议您只使用一个可能的副本,该链接与jQueryAjax api无关