返回 XML 的跨域 ajax 请求:Access-Control-Allow-Origin 不允许 Origin http://...
这是 jQuery 的一部分,它对我不起作用:
$.ajax({
crossDomain: true,
type: "POST",
url: "https://www.testdatasolutions.com/reportgw",
data: "ACCOUNT=creditreport123&PASSWD=asdj97sdf&PASS=2&PROCESS=PCCREDIT&NAME=Robert+Ice&SSN=891-42-3221&ADDRESS=111+W+8th+St&CITY=Fantasy+Island&STATE=IL&ZIP=60750&BUREAU=TU&PRODUCT=CREDIT&DEFAULTOUTPUT=XML"
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
输出错误显示:
XMLHttpRequest 无法加载 https://www.testdatasolutions.com/reportgw。 Access-Control-Allow-Origin 不允许来源 http://pmr.techforge.us。
可以在此处找到类似的主题< /a>,但它仅涵盖输出为 JSON 的情况。
所以我的问题是,是否可以处理返回 XML 的跨域 ajax 请求,或者我必须绝对使用 JSONP?
This is the piece of jQuery that's not working for me :
$.ajax({
crossDomain: true,
type: "POST",
url: "https://www.testdatasolutions.com/reportgw",
data: "ACCOUNT=creditreport123&PASSWD=asdj97sdf&PASS=2&PROCESS=PCCREDIT&NAME=Robert+Ice&SSN=891-42-3221&ADDRESS=111+W+8th+St&CITY=Fantasy+Island&STATE=IL&ZIP=60750&BUREAU=TU&PRODUCT=CREDIT&DEFAULTOUTPUT=XML"
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
The output error says:
XMLHttpRequest cannot load https://www.testdatasolutions.com/reportgw. Origin http://pmr.techforge.us is not allowed by Access-Control-Allow-Origin.
A similar topic can be found here, but it covers only the cases where output is in JSON.
So my question is, is it possible to handle cross domain ajax requests returning XML, or must I absolutely use JSONP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
必须是JSONP,默认不允许跨域请求XML。
然而,通过一些服务器端编程,您可以创建一个代理,并通过您自己域内的服务器端的curl 或类似方法加载数据,并将其输出为XML。这样您就可以访问自己域内的 url,而不必从客户端执行跨域请求,它是在“幕后”处理的。
It must be JSONP, XML is not allowed for cross-domain requests by default.
However, with a little server-side programing you could create a proxy and load the data through curl or similar on the server side within your own domain, and output it as XML. That way you can access an url within your own domain instead and you won't have to do a cross-domain request from the client, it is handled "behind the scenes".
您可以尝试使用 http://enable-cors.org/。您可以在 http://en.wikipedia.org/ 查看支持 CORS 的浏览器列表wiki/Cross-Origin_Resource_Sharing#Browser_support。
You can try with http://enable-cors.org/. You can check the list of browsers that support CORS at http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing#Browser_support.