【发布时间】: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