Last active
January 2, 2016 17:59
-
-
Save JacobBennett/8340607 to your computer and use it in GitHub Desktop.
handling ajax failures
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({}). | |
.done( | |
//200 returned but not well formed JSON string | |
if(!data.status) {return false;} | |
//200 with well formed JSON & an error | |
if(data.status === "fail") { | |
alert(data.message); | |
return false; | |
} | |
//200 with success | |
alert('returned succesfully'); | |
return true; | |
) | |
.fail( | |
//status code above 400 returned | |
alert(xhr.status); | |
return false; | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment