The Largest Free Web Script Directory Sites • FreeWebScript.com

jQuery Ajax Wait for Response

  • 92

jquery wait for all ajax requests to complete

//jQuery waiting for all ajax calls to complete b4 running
$.when(ajaxCall1(), ajaxCall2()).done(function(ajax1Results,ajax2Results){
    //this code is executed when all ajax calls are done
});
function ajaxCall1() {
    return  $.ajax({
        url: "some_url.php",
        success: function(result){
            console.log(result); 
        }
    });
}
function ajaxCall2() {
    return  $.ajax({
        url: "some_url.php",
        success: function(result){
            console.log(result); 
        }
    });
}

wait for ajax to finish

function functABC() {
  return new Promise(function(resolve, reject) {
    $.ajax({
      url: 'myPage.php',
      data: {id: id},
      success: function(data) {
        resolve(data) // Resolve promise and go to then()
      },
      error: function(err) {
        reject(err) // Reject the promise and go to catch()
      }
    });
  });
}

functABC().then(function(data) {
  // Run this when your request was successful
  console.log(data)
}).catch(function(err) {
  // Run this when promise was rejected via reject()
  console.log(err)

Free Download jQuery Ajax Wait for Response

Important! We update new contents like PHP Scripts, WordPress Themes, Plugins, Mobile App Templates Source Code or Article like jQuery Ajax Wait for Response for Web Development Business and Online Marketers everyday. But remember, if you getting some resource file from here that you should never use this items in a commercial website. All the file/contents posted here for development & testing purpose only. if this post contains shared file, I Recommended you buy source code for supporting the Developer. we do not store all the files on this website/host, Hence We Are Not Violating Any Terms.

Related Source jQuery Ajax Wait for Response

It Looks Like You Have AdBlocker Enabled

Please know that FreeWebScript.com relies solely on ads to keep producing and offering free content to you. We appreciate your disabling of Adblock to help support our site. If you have disabled ADBlock in your browser please Reload this Page.