Skip to content

Instantly share code, notes, and snippets.

@madpilot
Created November 30, 2011 02:49
Show Gist options
  • Save madpilot/1407763 to your computer and use it in GitHub Desktop.
Save madpilot/1407763 to your computer and use it in GitHub Desktop.
Replay an AJAX request if the first one failed due to an authentication error
jQuery.ajaxSetup(
statusCode: {
403: function() {
// This calls a backbone view that renders a login window, then
// calls the success function one the user has been authenticated
// The call back simply re-runs $.ajax using the current context object,
// which conveniently is a hash of the original AJAX request params.
var sessionLogin = new SessionsLoginView();
var context = this;
sessionLogin.render({
success: function() {
$.ajax(context);
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment