0
我想获得一些使用基于WCF Rest的服务的数据。XMLHTTPRequest不工作在浏览器,除了IE
这是我的代码。
jQuery.support.cors = true;
$.ajax({
url: http://localhost:2545/Service/GetData,
data: JSON.stringify(temp),
beforeSend: function (xhr) { xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); },
type: "POST",
contentType: "application/json charset=utf-8",
dataType: "Json",
crossdomain: true,
success: function (result) { ProximitySucceeded(result) },
error: function (result) { debugger; ServiceFailed(result) }
});
我的网站上运行http://localhost:1600和服务是http://localhost:2545。
它在IE上运行良好。但在铬/火狐/ Safari浏览器返回此错误 “来源http://localhost:1600是不允许的访问控制允许来源。”
请帮忙,因为服务不是从除IE以外的任何浏览器访问。
谢谢。 Mohit。
为什么你想使用'访问控制允许-Origin'为** **请求头? – Quentin
同意,Access-Control-Allow-Origin不应该在请求上设置,它应该由服务器在响应中设置。由于您正在将本地主机的请求发送到本地主机,您是否可以使用Wireshark来追踪正在进行的实际HTTP请求? – monsur