Cross domain ajax request returning XML: Origin http://… is not allowed by Access-Control-Allow-Origin

断了今生、忘了曾经 提交于 2019-12-11 07:47:54

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/9047155/cross-domain-ajax-request-returning-xml-origin-http-is-not-allowed-by-acc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!