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 6792401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:57:53+00:00 2026-05-26T17:57:53+00:00

I have a global handler for my AJAX calls $.ajaxSetup({ error: function(xhr, textStatus, errorThrown)

  • 0

I have a global handler for my AJAX calls

$.ajaxSetup({
    error: function(xhr, textStatus, errorThrown) {
             //do something 
    }
});

And in case of an error my servlet filter sends a specifc error

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {

    if(somethingwrong()) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "unavailableimage");    
    }
}

Would you recommend to do something like

$.ajaxError({
    error: function(xhr, textStatus, errorThrown) {
        if (xhr.status == 408) {
            //doSomething
        }
        else if xhr.responseText.contains("unavailableimage"){
            //doSomething
        }
    }
}); 

Because I think the responseText is different in every browser.

  • 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-05-26T17:57:54+00:00Added an answer on May 26, 2026 at 5:57 pm

    The response body is available by xhr.responseText.

    However, the HttpServletResponse#sendError() ( <– click the link to read the Javadoc yourself) will use the servletcontainer’s default error page template or your custom error page template as you’ve definied in web.xml. This is a HTML document which you thus have to parse yourself.

    As per your comment on the other answer, you seem to be using Tomcat and retrieving its default error page; the message is available as first <u> element of the second <p>. So this should do:

    var errorMessage = $(xhr.responseText).filter('p:eq(1)').find('u').text();
    
    if (errorMessage == 'unavailableimage') {
        // ...
    }
    

    You only need to keep in mind that you’re this way tight coupled to the markup of the (default) error page. Better is to not use HttpServletResponse#sendError(), but just set the status by HttpServletResponse#setStatus() ( <– yes, click it to read javadoc, the answer was in there) and write the error message to the response body yourself:

    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    response.getWriter().write("unavailableimage");
    

    This way the xhr.responseText is exactly unavailableimage.

    if (xhr.responseText == 'unavailableimage') {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have a global event handler for ajax requests that automatically
We have a global error handler in our ASP.NET application that logs and emails
In my adobe AIR application I have registered a global error handler. While debugging
I have a custom error handler in the global.asax's Application_Error method, when an error
VB 6.0 does not have any global handler.To catch runtime errors,we need to add
I have a general exception handler, Application_error in my global.asax where I'm trying to
I have an exception handler . In my asp.net application. It’s written in Global.asax.
We use jQuery's global ajaxError() handler to alert the user of any AJAX failures:
In .Net: 1) Do you let the exception propagate to the global error handler
I have the following jQuery Ajax call (There are no other global settings/handlers): $.ajax(

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.