Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:28:32+00:00 2026-06-15T09:28:32+00:00

My app uses $.ajax heavily. The server returns something like {STATUS:RELOGIN} in case the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:28:33+00:00Added an answer on June 15, 2026 at 9:28 am

    This is my idea(http://stackoverflow.com/questions/9815058/extending-jquery-ajax-success-globally):

    var LOGIN_ERROR_HAS_HAPPENED = false
    var INTERNAL_SERVER_ERRORS = false
    $(function(){
        var Original_AJAX_function = $.ajax;
        $.ajax = function(options){
            if(options.success){
                var original_callback = options.success
            }
            else{
                var original_callback = function(){}
            }
            options.success = function(data){
                if(data.STATUS == "RELOGIN") {
                    if(!LOGIN_ERROR_HAS_HAPPENED){
                        LOGIN_ERROR_HAS_HAPPENED = true
                        Notifier.warning("Login again. Redirecting to login page")
                        setTimeout(function(){
                            window.location.href = "/login"
                        }, 5000)
                    }
                    return
                }
                original_callback(data)
            }
            if(options.error){
                var original_failure_call_back = options.error
            }
            else{
                var original_failure_call_back = function(){}
            }
            options.error = function(data){
                if(!INTERNAL_SERVER_ERRORS||!LOGIN_ERROR_HAS_HAPPENED){
                    INTERNAL_SERVER_ERRORS = true
                    Notifier.warning("Oops! Something went wrong. Let us know and we will fix it" )
                }
                original_failure_call_back(data)
            }
            Original_AJAX_function(options)
        }
    })
    

    This I plan to put inside document.ready function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a web app that uses ajax to communicate with the server. Basically,
I have a nested form in my app that uses AJAX to load an
We have an ASP.NET 2.0 WebForms app that uses MS Ajax 1.0. It's working
I am creating a web app which uses jQuery to authenticate: $.ajax({ url: /session/create?format=json,
I've got an ASP.NET WebForms app that I've written, which uses the ASP.NET AJAX
Our app uses a component that requires a license file in the directory with
So, My app uses a ton of AJAX, and I find myself doing this
I've got an Ajax app I would like to add sessions and logins to.
I'm writing an AJAX web app that uses Comet/Long Polling to keep the web
Im building a codeigniter app which uses json_encode to provide ajax data in many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.