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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:54:26+00:00 2026-06-02T02:54:26+00:00

I want to know how can I handle errors using jquery $post from Struts2

  • 0

I want to know how can I handle errors using jquery $post from Struts2 action result.

For example in my strut2.xml I have handled the error using the following:

<action name="helloWorld" class="net.roseindia.Struts2HelloWorld">
   <result="success">/pages/HelloWorld.jsp</result>
   <result="error">/pages/HelloWorld.jsp</result>
</action>

In my jquery call, I have the following:

$.post("helloWorld", function(){

}).success(result){
    $("#div").html(result);
}).error(){
    alert("ERROR");  

};

Even if the result is equal to error, it always goes to success.

So how can I make the result=”error” go to $.post error in my jquery call?

  • 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-02T02:54:27+00:00Added an answer on June 2, 2026 at 2:54 am

    it is “success” because regardless of what “comes back” you will have an AJAX successful request/response. What you’ll need to do is set some “failure” notice from the servlet and then examine what comes back in the “success” block.

    “success” means the request returned a “2xx” code. “error” means a non-2xx success:

    more on html codes here : http://www.w3.org/Protocols/HTTP/HTRESP.html

    So like something like this (not useful code but you’ll get the idea)

    $.post("helloWorld", function(){
    
    }).success(result){
        if(result == some error condition) { this.error;} 
    else { //process the success
            $("#div").html(result);
    }
        }).error(){
        alert("ERROR");  
    
    };
    

    Edit: Below Anthony made a comment that since the user is in control of the service / page being requested – you can build the servlet / code in a way to return an html error code rather than interrogating the resulted html – this is a great suggestion. Thank you Anthony

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

Sidebar

Related Questions

I want to know how can I perform VS2008 load test from five different
I want to know how can I read attachment messages without using scriplets in
I want to pass data from client side to server-side. I am using jQuery
I want to know how can we know the other users of Oracle 10g
I want to know how can i fill only certain columns while filling the
I want to know that can mouse click event detects colors or even strings.
I want to know i can do something similar to this (not working) code
I want to know how can i format a number like 2000000 into standard
I just want to know: How can I delete 'log.txt' if the last modification
I'm learning PLT Scheme and I want to know how can I build a

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.