[英]Cross domain error handling and WCF
I am using a cross domain jQuery ajax call to my WCF webservice. 我正在对WCF Web服务使用跨域jQuery Ajax调用。 I was using the approach CORS,but the error block is not firing for me. 我使用的是CORS方法,但是错误块对我没有触发。 When I tried the jsonp approach it is firing. 当我尝试jsonp方法时,它正在触发。 Please have alook into the code. 请看一下代码。
CORS: 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);
}
});
}
Service:- 服务:-
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "ErrorHandling")]
string ErrorHandling();
Thanks. 谢谢。
I am not sure why it was not firing earlier. 我不知道为什么它不早点开火。 Now it is working fine. 现在工作正常。 Here is my code. 这是我的代码。
$.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);
}
});
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.