Skip to content

Instantly share code, notes, and snippets.

@twetzel
Created June 21, 2012 22:08
Show Gist options
  • Save twetzel/2968873 to your computer and use it in GitHub Desktop.
Save twetzel/2968873 to your computer and use it in GitHub Desktop.
Handle spine ajax errors with jQuery .. by Ian White
Handle global ajax errors with jQuery:
$(document).ajaxError (xhr, status, error) =>
console.log("Global ajaxError", arguments)
if xhr.status is 403
window.location = "http://backend.myapp.com/login"
Handle individual jQuery ajax requests:
$.ajax(
url: url
).done((result, status, xhr) =>
# The request was successful
@user = result.user
).fail((xhr, status, error) ->
# The request failed, check for a 403 error (or any response code) here
if xhr.status is 403
window.location = "http://backend.myapp.com/login"
)
Handle ajax errors on a specific Spine Model:
Person.bind "ajaxError", (record, xhr, settings, error) =>
console.log("Person", "ajaxError", arguments)
if xhr.status is 403
window.location = "http://backend.myapp.com/login"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment