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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:01:08+00:00 2026-05-26T18:01:08+00:00

$.ajax(example.php).done(function () { alert(…); }).fail(function () { alert(…); }).always(function () { alert(…); }); vs

  • 0
 $.ajax("example.php").done(function ()
 {
     alert(...);
 }).fail(function ()
 {
     alert(...);
 }).always(function ()
 {
      alert(...);
 });

vs

  $.ajax("example.php",

      success: function ()
      {
          alert('');
      },
      error: function ()
      {
          alert('');
      },
      complete: function ()
      {
          alert('');
      }
  );

Sorry , I can’t see any advantages

Can you please explain ?

Or maybe can you give me example of the former which cant be accomplished by the latter…?

  • 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-26T18:01:08+00:00Added an answer on May 26, 2026 at 6:01 pm

    For starters, the second code block isn’t even syntactically valid. I’d call that an advantage of the first :P


    But in all seriousness:

    It’s just a different syntax for achieving the same end result. One immediate advantage is that you can wire up multiple functions for each outcome with deferred:

    $.get("example.php").done(function ()
    {
        alert("success 1");
    }).done(function ()
    {
        alert("success 2");
    });
    

    otherwise you’d have to do it like so:

    function done1()
    {
        alert('success 1');
    }
    function done2()
    {
        alert('success 2');
    }
    
    $.ajax('example.php',
    {
        success: function ()
        {
            done1.apply(this, arguments);
            done2.apply(this, arguments);
        }
    });
    

    Other advantages, quoted from How can jQuery deferred be used?

    • Deferreds are perfect for when the task may or may not operate asynchronously, and you want to abstract that condition out of the code.
    • …Fetching data from multiple sources. In the example below, I’m fetching multiple, independent JSON schema objects used in an existing application for validation between a client and a REST server. In this case, I don’t want the browser-side application to start loading data before it has all the schemas loaded. $.when.apply().then() is perfect for this.
    • A deferred can be used in place of a mutex. This is essentially the same as the multiple ajax usage scenarios.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw in jQuery the code : var jqxhr = $.ajax( example.php ) .done(function()
//******************Example for multiple ajax success and failure*************// function doAjax1(){ var data=ajax_mode=request1&sample_data1=sample_data1; return $.get(ajax.php,data,function(msg){ //alert(msg);
I'm using JQTOUCH using the AJAX example provided in the demo: $('#customers').bind('pageAnimationEnd', function(e, info){
Can I have good example or code about how to use Ajax Datepicker in
For example, i'm using the beforeSend option in the $.ajax function. In the code
Please can you suggest me an example in classic asp and ajax to make
if so can show simple example, ex in jquery ajax.post
Currently users can search a database using php and ajax with the results shown
This is my code, $.ajax({ type:get, //this doesn't work //url:'http://example.com/json.php', //But this works url:'http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?',
I have a simple example of PHP sessions and AJAX, which works when holding

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.