jquery / ajax / soap - access-control-allow-origin

和自甴很熟 提交于 2019-12-20 04:50:05

问题


I'm trying to access a SOAP web service using jquery / ajax and getting an access control allow origin error:

XMLHttpRequest cannot load https://site.com/service/Service.asmx?op=LoginConsumer. Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin

Is there a way around this? Are their certain things I need to do to set this up? I've been told that there are no access controls in place yet. I'm testing from a local server (localhost).

I'm following this tutorial:

http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/


回答1:


You seem to be violating the same origin policy restriction. You cannot send AJAX requests to different domains.




回答2:


Try creating a fetchSoap.php page on localhost that fetches the data from site.com and simply echos it. Then you can fetch the data from localhost/fetchSoap.php and you will not be violating same origin policies.

The PHP code would be (you can use any language you're currently using)

http://localhost/FetchSOAP.php

 <?php
     die( file_get_contents( 'http://site.com/PathToSoap/' ) );
 ?>


来源:https://stackoverflow.com/questions/7288993/jquery-ajax-soap-access-control-allow-origin

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