[英]Cross domain error handling and WCF
我正在对WCF Web服务使用跨域jQuery Ajax调用。 我使用的是CORS方法,但是错误块对我没有触发。 当我尝试jsonp方法时,它正在触发。 请看一下代码。
CORS:
function faultCLick() {
$.support.cors = true;
$.ajax({
url: "http://mydomain:84/AuthService.svc/ErrorHandling",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function res(msg) {
jsonpTest = msg;
alert("inside success ");
},
error: function (message) { // not firing
debugger;
var jsonFault = JSON.parse(message.responseText);
alert(jsonFault.Message);
}
});
}
服务:-
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "ErrorHandling")]
string ErrorHandling();
谢谢。
我不知道为什么它不早点开火。 现在工作正常。 这是我的代码。
$.support.cors = true;
$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json;charset=utf-8",
url: "http://mydomain:89/MyAppAppService.svc/GetFolders",
success: function (msg) {
alert("Success");
},
error: function (jqXHR, status, message) {
alert(jqXHR.responseText);
alert(status + " " + message);
}
});
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.