有没有办法通过简单地查看代码来判断是否在某处记录了 ajax 错误?
我们有一个页面的副本,它会抛出错误,因为我们没有登录。。.. 但我们并不真正关心登录,因为我们实际上只是在测试和移动代码等。但我们不是代码的原始所有者,所以我们从字面上复制了元素并只是在玩功能在本地服务器上。我们只是不希望可怜的程序员在我们只是移动和玩代码时遇到大量错误并变得笨拙。
我们关心的代码是:
//----------------------------- Called each time the page is loaded -------//
function init(){
//launch session time out counter
startSession();
//store Q answers
//$('#questionnaire').data('firstChange', true);
$('#questionnaire').data('q1', $('[name="A"]:checked').val());
$('#questionnaire').data('q2', $('[name="B"]:checked').val());
$('#questionnaire').data('q3', $('[name="C"]:checked').val());
$('#questionnaire').data('q4', $('[name="D"]:checked').val());
//reset flags
$('#content').data('clickBound', true);
$('#content').data('payerJson', null);
$('#content').data('myValidator', null);
//Handle different types of Ajax errors
$.ajaxSetup({
error:function(x,e){
if(x.status==0 || x.status==401){
var answer = confirm("You're logged out the application. Click on \"Ok\" to log in again.");
if(answer){
window.location="./";
}
}else if(x.status==404){
alert('Requested URL not found. Please check your network connection and try to log in again.');
}else if(x.status==500){
alert('Internal Server Error. Please try to log out and log in again.');
}else if(e=='parsererror'){
alert("Error.\nParsing Request failed. Please try to log out and log in again.");
}else if(e=='timeout'){
alert('Request Time out. Please check your network connection and try to log in again.');
}else {
alert("Unknown Error.\n"+x.responseText + "\n Please try to log out and log in again on.");
}
},
cache : false
});