2

我正在尝试从不属于我的服务中获取一些 xml 信息。基本上,用户将在其他服务上进行身份验证,我的脚本应该通过跨站点使用身份验证 cookie 获取信息。

我正在使用 jquery 来执行此操作,并且我可以看到我想要处理的响应是由服务返回的(通过 firebug),问题是我正在使用 jsonp 进行调用,所以 jquery 返回一个解析错误.

我已经尝试了我遇到的所有解决方案来执行这种操作,比如 YQL 和代理服务器。

我在这里的挫败感是我看到了我想要的响应,但 jquery 只是不给我原始信息。

我知道我正在调用一个需要 json 响应的函数,但是没有任何解决方法或其他方法吗?像xmlp xD。

$.ajax(
        {
            url: "serviceurl",

            dataType: 'jsonp', //I've tried 'jsonp xml'


            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            success: function()
            {
                alert('Load was performed.');
            },

            error: function(jqxhr,error) 
            { 
                alert('Failed!'); 
            },

        });

编辑:这是服务器的输出

<User>
 DVD_PT
</User>
<Apps>
 <App>
   <name>Last.fm Scrobbler</name>
 </App>
</Apps>

谢谢

4

1 回答 1

0

除非其他域支持 CORS,否则根本不可能从跨域源请求 XML。

正如您已经提到的,您必须使用某种代理,例如 YQL。

将数据类型设置为 JSONP 时看到的响应位于<script>标记内。例如,你得到这个:

<script src="http://example.com/note.xml"></script>

其中 note.xml 是:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

这当然会引发错误,因为它不是有效的javascript。

于 2012-02-17T16:43:35.747 回答