My app uses $.ajax heavily. The server returns something like {"STATUS":"RELOGIN"} in case the login has expired. Our app is such that the logout on the server happens if the user does nothing for 20 minutes on the app.
All the posts and gets happen through $.ajax and I want to globally change the $.ajax function so that in case the data returned for a request is {"STATUS":"RELOGIN"} I want to make sure that the user is shown some notification if this happens.
I can put this is as the success handler for all the request
function(data){
if(data.STATUS == "RELOGIN") {
Notifier.show_error("Login again. Session has expired")
return
}
// rest of the code depending on the request
}
Where Notifier is something that I have written to show notifications
But I do not think duplication of this code in too many places is a good idea.
I do not want to touch jquery source code. It is beautiful as it is.
This is my idea(http://stackoverflow.com/questions/9815058/extending-jquery-ajax-success-globally):
This I plan to put inside document.ready function