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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:24:41+00:00 2026-05-23T00:24:41+00:00

By using jquery ajax function, I can do something like: $.ajax({ url: url, type:

  • 0

By using jquery ajax function, I can do something like:

$.ajax({

  url: url,
  type: 'GET',
  async: true,
  dataType: 'json',
  data: data,

 success: function(data) {

     //Handle server response here

  },

 error: function(xhr, status, error){

    //Handle failure here

 }

});

I got two questions to ask based on above code:

  1. When will the jquery.ajax() error callback be called??

  2. What if server response to me a json object with string message “There is an error“. Which means the request is still send successfully, but I got server response {message: "There is an error"}.

I think no matter what string value server is responsed, if client got server’s response, the jquery.ajax() success callback will be triggered anyway.

I’d like to ask if server specifically returns to me a JSON object with string value like {message: 'There is an error'}, could server do something so that this response could be handled in jquery.ajax() error callback instead of success callback?

  • 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-23T00:24:42+00:00Added an answer on May 23, 2026 at 12:24 am

    The error callback will be executed when the response from the server is not going to be what you were expecting. So for example in this situations it:

    • HTTP 404/500 or any other HTTP error message has been received
    • data of incorrect type was received (i.e. you have expected JSON, you have received something else).

    In your situation the data is correct (it’s a JSON message). If you want to manually trigger the error callback based on the value of the received data you can do so quite simple. Just change the anonymous callback for error to named function.

    function handleError(xhr, status, error){
    
        //Handle failure here
    
     }
    
    $.ajax({
    
      url: url,
      type: 'GET',
      async: true,
      dataType: 'json',
      data: data,
    
     success: function(data) {
         if (whatever) {
             handleError(xhr, status, ''); // manually trigger callback
         }
         //Handle server response here
    
      },
    
     error: handleError
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I make an AJAX request like so using JQuery: $.ajax({ type: GET, url: getvideo.php,
I'm using this jQuery code: $.ajax ({ type: POST, url: customerfilter.php, data: dataString, cache:
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
normally my ajax functions look something like this: function ajaxCallback(url,functionToRun) { if (window.XMLHttpRequest) {//
I am using MVC3 Jquery and AJAX to produce something like List/Details view. Now
I am using the $.ajax function in jquery to make a call to an
When using jQuery 's ajax method to submit form data, what is the best
I am starting to use the jquery $.ajax() but I can't get back what
So, I have a function that looks something like this: function getUnits(squad_id) { $.ajax({
I would like to have a function that returns the repsonseText of a jQuery.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.