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

  • Home
  • SEARCH
  • 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 6658667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:56:25+00:00 2026-05-26T01:56:25+00:00

I have a set of $.get() requests that I need to refactor to include

  • 0

I have a set of $.get() requests that I need to refactor to include a failure callback. The requests are of the form

$.get(url,
      {},
      function(data) {//success, do work
      //work
      },'json');//or 'html'

According to the jQuery API, I simply add a jqHXR object. So in my case, I believe I should do

var jqxhr =  $.get(url,
          {},
          function(data) {//success, do work
          //work
          },'json').error(function() { alert("error"); });//or 'html'

I don’t understand the reason for the second success callback in the example. I suppose it could be there for setting up a callback chain. I want error to execute in error, and success to execute on success. So, is this correct?

  • 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-26T01:56:26+00:00Added an answer on May 26, 2026 at 1:56 am

    I think the second success callback in the example is just there to illustrate that, using this syntax, you can have multiple handlers for success, error, and complete events. In the standard jQuery .ajax() method, you can only assign a single handler to each of these events. I can’t think offhand of an example that would require multiple handlers, but it does seem a little clearer and more like the standard jQuery idiom to use

    $.get('my_url.php')
        .success(handlerOne)
        .success(handlerTwo);
    

    instead of

    $.get('my_url.php', function(data, textStatus, jqXHR) {
        handlerOne(data, textStatus, jqXHR);
        handlerTwo(data, textStatus, jqXHR);
    });
    

    In your case, though, it might be easier and cleaner to just convert your $.get() statements to $.ajax(). The $.ajax() syntax is probably more familiar to most jQuery programmers, and since you don’t need the special functionality (multiple handlers, post-request handler assignment) available in the other syntax, there’s no reason not to just use $.ajax():

    $.ajax({
        url: url,
        success: function(data) {
            // success, do work
        },
        error: function(data) {
            // error, handle failure
        },
        dataType:'json'
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a page that loads and through jquery.get makes several requests to
I have - class A { // contains certain set() and get() methods }
I have a script to get and set user's Windows environment variables on other
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have code in javascript which get keycodes of different keys and set it
I have a three tier set-up. Someone suggested I should get the ConnectionString from
I have two classes class A { public string something { get; set; }
I have the following property public MyType MyProperty {get;set;} I want to change this
I'm building a set of pages where I have a number of GET variables
I have an automatic property public int GearCount { get; set; } when i

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.