调用webservice可以在IE上运行,而不是从Chrome或Firefox运行

时间:2015-04-30 17:49:19

标签: ajax web-services cors

我在我网站的同一个域中有一个网络服务。我有一个ajax调用来咨询该webservice并且可以在IE中正常工作,但是从Chrome和Firefox开始,我无法使其工作。

我的ajax电话是:

       $.ajax({
        type: 'POST',
        async: false
        data: xml,
        url: url,
        dataType: "xml",
        success: function (data, textStatus, XmlHttpRequest) {
           //On sucess action
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
           //On error action
        },
        headers: {
            "Content-Type": "text/xml; charset=utf-8",
            "SOAPAction": soapAction,
            "Content-Length": xml.length + 1
        }
    });

但是从chrome和firefox我收到:

 XMLHttpRequest cannot load https://mydomain:83/<webservice>/<webservice>.asmx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mydomain' is therefore not allowed access. The response had HTTP status code 500.

我添加到webconfig:

   <system.webServer>
<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="https://mydomain"/>
    <add name="Access-Control-Allow-Origin" value="http://mydomain"/>
    <add name="Access-Control-Allow-Credentials" value="true"/>
  </customHeaders>
</httpProtocol>

但没有运气。知道我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

我很快就放弃了。在我的特定情况下,这可以解决Chrome和Firefox的问题

 <add name="Access-Control-Allow-Origin" value="https://mydomain" />
 <add name="Access-Control-Allow-Headers" value="Content-Type, SOAPAction" />
 <add name="Access-Control-Allow-Methods" value="GET, POST" />