Skip to content

Instantly share code, notes, and snippets.

@JacobBennett
Last active January 2, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobBennett/8340607 to your computer and use it in GitHub Desktop.
Save JacobBennett/8340607 to your computer and use it in GitHub Desktop.
handling ajax failures
$.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