[英]how to test a Global AJAX error handling
我以这种方式设置了全局AJAX错误处理功能,但是我看不到如何测试它? 无论如何在jsFiddle中
$(function () {
var statusErrorMap = {
'400' : "Server understood the request, but request content was invalid.",
'401' : "Unauthorized access.",
'403' : "Forbidden resource can't be accessed.",
'500' : "Internal server error.",
'503' : "Service unavailable."
};
//setup ajax error handling
$.ajaxSetup({
error: function (x, status, error) {
if (x.status in statusErrorMap) {
if (x.status == "503") {
alert("Sorry, your session has expired. Please login again to continue");
window.location.href ="/users/sign_in";
} else {
alert("("+ x.status +") error occurred: " + statusErrorMap[x.status.toString()]);
}
}
else {
alert("An error occurred: " + status + "nError: " + error);
}
}
});
});
您必须使用fiddler(代理工具)来拦截服务器请求并测试您的错误处理代码。 为此,您必须在fiddler中为服务调用设置一个断点,然后执行以下过程。
您可以在下面的stackoverflow中获取详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.