jquery Ajax $.ajaxError
Posted
by cf_PhillipSenn
on Stack Overflow
See other posts from Stack Overflow
or by cf_PhillipSenn
Published on 2010-04-06T18:19:42Z
Indexed on
2010/04/06
18:23 UTC
Read the original article
Hit count: 281
jQuery
I have a bunch of ajax calls that contain success and error conditions like this one:
$.ajax({
url: 'Remote/State.cfc'
,type: "POST"
,data: {
'method': 'UpdateStateName'
,'StateID': StateID
,'StateName': StateName
}
,success: function(result){
if (isNaN(result)) {
$('#msg').text(result).addClass('err');
} else {
$('#' + result + ' input[name="StateName"]').addClass('changed');
};
}
,error: function(msg){
$('#msg').text('Connection error').addClass('err');
}
});
All the error conditions are the same. In other words, they all put the phrase "Connection error" in the msg id.
Q1: Could I remove all these and replace them with
$().ajaxError(function(myEvent, request, settings, thrownError) {
$('#msg').text('Connection error').addClass('err');
});
Q2: How would you use myEvent and request to display a more informative error message?
© Stack Overflow or respective owner