jQuery Ajax Error Handling

[javascript]
$.ajax({
url: ”,
type: ‘POST’,
dataType: ‘json’,
data: {},
beforeSend: function(){
$(‘#load-msg’).show();
},
success: function(data) {
$(‘#load-msg’).hide();
if(data.errorStatus){
alert(data.errorMsg || ‘An error has occurred’);
}else{
// do stuff
}
},
error: function() {
$(‘#load-msg’).hide();
alert(‘An error has occurred’);
}
});
[/javascript]

Leave a Reply