跨域ajax请求返回XML:原产地http:// ...不允许由Access-Control-Allow-Origin [英] Cross domain ajax request returning XML: Origin http://... is not allowed by Access-Control-Allow-Origin

查看:529
本文介绍了跨域ajax请求返回XML:原产地http:// ...不允许由Access-Control-Allow-Origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是jQuery的一块对我不起作用:

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 );
});

输出错误说:


XMLHttpRequest无法加载 https://www.testdatasolutions.com/reportgw 。 Access-Control-Allow-Origin不允许原始 http://pmr.techforge.us

XMLHttpRequest cannot load https://www.testdatasolutions.com/reportgw. Origin http://pmr.techforge.us is not allowed by Access-Control-Allow-Origin.

可以找到类似的主题此处,但仅涵盖输出为JSON的情况。

A similar topic can be found here, but it covers only the cases where output is in JSON.

所以我的问题是,是否可以处理跨域ajax请求返回XML,或者必须绝对使用JSONP

So my question is, is it possible to handle cross domain ajax requests returning XML, or must I absolutely use JSONP?

推荐答案

它必须是JSONP,默认情况下不允许跨域请求。

It must be JSONP, XML is not allowed for cross-domain requests by default.

但是,通过一些服务器端程序,创建代理并通过curl或类似的方式在您自己的域中的服务器端加载数据,并将其输出为XML。这样,您可以访问自己域内的网址,而不必从客户端执行跨网域请求,因此会在幕后处理。

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".

这篇关于跨域ajax请求返回XML:原产地http:// ...不允许由Access-Control-Allow-Origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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