Skip to content

Instantly share code, notes, and snippets.

@mattgd
Last active October 23, 2018 21:49
Show Gist options
  • Save mattgd/beccb7e807260307004b524aac260827 to your computer and use it in GitHub Desktop.
Save mattgd/beccb7e807260307004b524aac260827 to your computer and use it in GitHub Desktop.
AJAX Request Debug Example
$.ajax({
url: 'submit.php',
data: $(this).serialize(),
type: 'POST',
dataType: 'json',
success: function(data) {
if (data.status == 0) {
alert('You are offline!\nPlease check your network connection.');
} else if (data.status == 404) {
alert('Requested URL not found.');
} else if (data.status == 500) {
alert('Internal server error.');
} else if (e == 'parsererror') {
alert('Error.\nParsing JSON request failed.');
} else if(e == 'timeout') {
alert('Request timed out.');
} else {
alert('Unknown error.\n' + data.responseText);
}
if (data.status == 'success') {
alert("Request complete!");
} else if (data.status == 'error') {
alert("Error completing request!");
}
},
error: function(data) {
alert("There was an error. Please try again.");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment