multiple ajax hit in one request jquery

Most of the programmer knows about the ajax but they may be used it only for one hit. But in case if we need to make multiple ajax hits in one request then what?

Today I am going to show how we can make multiple ajax hits in one request.

var id=123;
var jqxhr = $.ajax({
                type: "POST",
                url: urlhere,
                data: { id : id},
                dataType: "json",
}).done(function() {
    alert( "success first" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "complete" );
  }); 

// second ajax hit after compeletion first
jqxhr.always(function() {
  alert( "second complete" );
});

// third ajax hit after compeletion second
jqxhr.always(function() {
  alert( third complete" );
});

Hope this help you to achieve multiple ajax hits in one request.
happy coding…

Posted by | View Post | View Group