我正在调用(Ajax请求)一个WCF REST服务,并且请求是跨域请求。跨域jQuery Ajax请求和WCF REST服务
如果我在同一个域中部署我的服务,那么所有的工作都像奶油一样。最终在生产中,该服务将处于不同的领域。
我正在使用jQuery 1.5.2。我的服务返回我一个错误说:
errorThrown: "jQuery15208493315000087023_1334089616458 was not called"
textStatus: "parsererror"
虽然在Firefox中,我可以看到的JSON值,但执行降到Ajax请求的错误处理程序。
我的Ajax请求是:
function CallService() {
$.ajax({
type: "GET",
url: "http://SomeService/EmpService.svc/GetValues?dv=1455",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata: false,
success: function (data) {
ServiceSucceeded(data);
},
error: function (jqXHR, textStatus, errorThrown) {
debugger;
alert("Service Error");
ServiceFailed(jqXHR, textStatus, errorThrown);
}
});
}
在WCF服务的一面,我已经配置CrossDomainScriptAccess为true:
<webHttpBinding>
<binding name="webHttpBindingWithJsonP"
crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
JSON响应这是我从服务器得到的是:
[{"Message": "Stop On Duty", "MessageTime": "\/Date(1334068773893-0500)\/"},
{"Message": "Start On Duty", "MessageTime": "\/Date(1334068763540-0500)\/"},
{"Message": "App_testing_4102012924am", "MessageTime": "\/Date(1334068533627-0500)\/"},
{"Message": "Kunal_testing_4102012924am", "MessageTime": "\/Date(1334067945510-0500)\/"},
{"Message": "Alert: Door Open", "MessageTime": "\/Date(1334066280963-0500)\/"}]
我在设置中遗漏了什么。如果服务移动到同一个域,整个代码都可以正常工作。
我看着类似的帖子,但无法做到这一点。
,我希望你也加入了跨域策略文件,点击这里http://msdn.microsoft.com/en-us/library/cc197955%28v = vs.95%29.aspx – Chandermani 2012-04-11 06:40:20
是的,根目录 – 2012-04-11 13:36:00