【问题标题】:Call webservice works from IE, not from Chrome or Firefox从 IE 调用 webservice 工作,而不是从 Chrome 或 Firefox
【发布时间】:2015-07-10 13:21:10
【问题描述】:

我在我的网站的同一个域中有一个网络服务。我有一个 ajax 调用来咨询该 Web 服务,并且在 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>

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

【问题讨论】:

    标签: ajax web-services cors


    【解决方案1】:

    我很快就放弃了。在我的特殊情况下,这对 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" />
    

    【讨论】:

      猜你喜欢
      • 2016-02-05
      • 2015-02-28
      • 2010-09-21
      • 2011-09-28
      • 1970-01-01
      • 2015-07-11
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多