Last active
October 23, 2018 21:49
-
-
Save mattgd/beccb7e807260307004b524aac260827 to your computer and use it in GitHub Desktop.
AJAX Request Debug Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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