【发布时间】:2015-06-24 03:46:40
【问题描述】:
我在 IIS 7.5 上发布了我的服务,但我无法在 Ajax 中调用我的服务 ,应该注意的是,我在我的服务上设置了所有的交叉设置,当使用 Ajax 调用服务时,我在控制台中收到两个警告:
1-Cross-Origin Request Blocked:同源策略不允许读取http://84.241.41.5:8000/Sale.svc/GetDataReportSaleOfMonth 的远程资源。 (原因:CORS 标头 'Access-Control-Allow-Origin' 不匹配 '*, *')。
2-跨域请求被阻止:同源策略不允许读取位于http://84.241.41.5:8000/Sale.svc/GetDataReportSaleOfMonth 的远程资源。 (原因:CORS 请求失败)。
URL of my service activate in address
我的 Ajax 代码是:
$.ajax({
type: "Get",
url: "http://84.241.41.5:8000/Sale.svc/GetDataReportSaleOfMonth",
contentType: "application/json;charset-uf8", // content type sent to server
dataType: "json", //Expected data format from server
crossDomain: true,
success: function(response) {//On Successfull service call
ServiceSucceeded(msg);
},
error: function (response, errorText) {
ServiceFailed(response);
}// When Service call fails
});
});
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
function ServiceSucceeded(result) {
alert("ok");
}
请帮助我了解我在 Ajax 中的服务出错的原因。
【问题讨论】: