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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:06:08+00:00 2026-06-05T23:06:08+00:00

Within my ajax call if an error is received I have an alert :

  • 0

Within my ajax call if an error is received I have an alert :

    $.ajax({
        url: "myUrl",       
        type: 'POST',
        dataType : "text",
        data : ({
            json : myJson
        }),
        success : function(data) {
                 alert('success');
    },
    error : function() {
                alert ('error');
    } 

From within java is it possible to send back to invoke the error callback in jquery if an exception is thrown. So something like :

    try {
        PrintWriter out = resourceResponse.getWriter();
        out.println("success");
        out.close();
    } catch (Exception e) {
        PrintWriter out = resourceResponse.getWriter();
        out.println("error");
        out.close();
    }

i.e instead of printing “error” on the response, invoke the ‘error’ callback within the jQuery code.

  • 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-05T23:06:10+00:00Added an answer on June 5, 2026 at 11:06 pm

    You have to set a http status code of something other than 200 to invoke the error callback in jQuery Ajax. You can set a error staus of 500 (which is for Internal Server Error) like

    catch (Exception e) {
        resourceResponse.setProperty(resourceResponse.HTTP_STATUS_CODE, "500"); 
        PrintWriter out = resourceResponse.getWriter();
        out.println("error");
        out.close();
    }
    

    in your catch block.

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

Sidebar

Related Questions

I have a jQuery .ajax call: $j.ajax({ type: POST, url: /Services/Cart.asmx/UpdateQuantity, data: data, contentType:
I have a simple ajax call: $.ajax({url: my_url_here, dataType: 'text', success: function(data, textStatus) {
I have some JavaScript that is making an Ajax call to a relative url
I need to use the $.ajax() call within jQuery to post a little bit
I'm trying to do a cross domain ajax post request within ie. Here is
The problem seems very strange. I have a AJAX helper function within a same
The following code is within an ajax call. I'm trying to make sure people
I have an Ajax call written in prototype and need to convert it to
I have a generic ajax Error handler written like so: $('html').ajaxError(function(e, xhr, settings, exception)
I am making an Ajax call within my page to a DB and pulling

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.