jQuery Ajax Error Handling

$.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');
	}
});

Leave a Reply