jQuery : ajax 에러 처리

$.ajaxSetup({
error:function(x,e){
if(x.status==0){
alert('네트워크를 체크해주세요.');
}else if(x.status==404){
alert('페이지를 찾을수없습니다.');
}else if(x.status==500){
alert('서버에러 발생하였습니다.');
}else if(e=='parsererror'){
alert('Error.nParsing JSON Request failed.');
}else if(e=='timeout'){
alert('시간을 초과하였습니다.');
}else {
alert('알수없는 에러가 발생하였습니다.n'+x.responseText);
}
}
});

$().ready(function(){
$.ajaxSetup({
error:function(x,e){
if(x.status==0){
alert('You are offline!!n Please Check Your Network.');
}else if(x.status==404){
alert('Requested URL not found.');
}else if(x.status==500){
alert('Internel Server Error.');
}else if(e=='parsererror'){
alert('Error.nParsing JSON Request failed.');
}else if(e=='timeout'){
alert('Request Time out.');
}else {
alert('Unknow Error.n'+x.responseText);
}
}
});
});

http://www.maheshchari.com/jquery-ajax-error-handling/

Leave a Reply

Your email address will not be published.