cross-domain AJAX post call

跟風遠走 提交于 2019-12-20 14:36:19

问题


I've to make a POST call(with parameter) to an asp form which is located on another server.

For development, I did this on the same server, and it works perfectly, but now I'm testing it on another server, and instead of receiving a 200 status, I receive a 0 status.

I think it's because it's a cross-domain AJAX call, it's the only thing which changed. So how can I make this call? Is there any file I can put on the server/client to allow this call(like flash, ...)?

Thank you!


回答1:


Yes, assuming you can change the server you connect to

You can implement Cross Origin Resource Sharing (CORS)

You need the server to return Access-Control-Allow-Origin: * if you want to allow all domains to access, otherwise return Access-Control-Allow-Origin: http://yourdomain.com

If you cannot change the server you are accessing, you need to use a proxy on the server your script comes from - alternatively investigate if they have published an API to return for example JSONP

More details here

  • MDN HTTP access control (how)
  • W3Org (Implemation details)
  • MSDN XDR

and several links to the right of this questions




回答2:


You can either create a proxy script, or use jsonp. The easier course would be to use a proxy script on your server.



来源:https://stackoverflow.com/questions/6812331/cross-domain-ajax-post-call

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