JavaScript Loading AJAX calls one after the other loading ajax function,ajax loading call,loading while ajax call,

I'd suggest you chain them with promises:

// Retrieve last 9 session
$.ajax({
    type: "POST",
    data: {
        run: true,
        providerName: $('#providerName').val()
    },
    url: '/app/functions/sessionAllCoursePage1.php',
    cache: false
}).then(function(response) {

    $('#contentPage1').html(response);

    return $.ajax({
        type: "POST",
        data: {
            run: true,
            providerName: $('#providerName').val()
        },
        url: '/app/functions/sessionAllCoursePage2.php',
        cache: false
}).then(function(response) {

    $('#contentPage2').html(response);

    return $.ajax({
        type: "POST",
        data: {
            run: true,
            providerName: $('#providerName').val()
        },
        url: '/app/functions/sessionAllCoursePage3.php',
        cache: false
    });    
}).then(function(response) {
    $('#contentPage3').html(response);
});

Or, using a little more shared code:

function ajaxCommon(url, resultId) {
    return $.ajax({
        type: "POST", 
        url: url, 
        data: {
            run: true,
            providerName: $('#providerName').val()
        },
        cache: false
    }).then(function(result) {
        $("#" + resultId).html(result);
    });
}

ajaxCommon('/app/functions/sessionAllCoursePage1.php', 'contentPage1').then(function() {
    return ajaxCommon('/app/functions/sessionAllCoursePage2.php', 'contentPage2');
}).then(function() {
    return ajaxCommon('/app/functions/sessionAllCoursePage3.php', 'contentPage3');
});

Or, a little more table/loop driven:

function ajaxCommon(url, resultId) {
    return $.ajax({
        type: "POST", 
        url: url, 
        data: {run: true, providerName: $('#providerName').val()},
        cache: false
    }).then(function(result) {
        $("#" + resultId).html(result);
    });
}

[1,2,3].reduce(function(p, item) {
    return p.then(function() {
        return ajaxCommon('/app/functions/sessionAllCoursePage' + item + '.php', 'contentPage' + item);
    });
}, Promise.resolve());
Answer:1

Just place your asynchronous code inside some request callback (e.g. success). Didactically:

var firstRequestOptions = {
  success: function () {
    secondRequest(); 
  }
};
var secondRequestOptions = {
  success: function () {
    thirdRequest(); 
  }
};
var thirdRequestOptions = {
  success: function () {
    firstRequest(); 
  }
};
var firstRequest = function () {
  console.log('request 1'); 
  $.ajax(firstRequestOptions); 
};
var secondRequest = function () { 
  console.log('request 2'); 
  $.ajax(secondRequestOptions);
};
var thirdRequest = function () { 
  console.log('request 3'); 
  $.ajax(thirdRequestOptions); 
};

Then:

firstRequest();

The log should be:

> request 1
> request 2
> request 3
> request 1
> request 2
...
Answer:2

I'm using the Google Tag Manager (GTM) with E-Commerce-Tracking. The Shop-System sends the following information to the GTM: dataLayer = [{ "event":"transaction", "transactionId":"100002486", "...

I'm using the Google Tag Manager (GTM) with E-Commerce-Tracking. The Shop-System sends the following information to the GTM: dataLayer = [{ "event":"transaction", "transactionId":"100002486", "...

I have a problem with chrome scrollbar,on Mozilla there is no such a problem. I have couple of synchronous ajax requests and then some info appending on the page,they need about 2 secs to load.During ...

I have a problem with chrome scrollbar,on Mozilla there is no such a problem. I have couple of synchronous ajax requests and then some info appending on the page,they need about 2 secs to load.During ...

  1. google chrome scroll bar
  2. google chrome scroll speed
  3. google chrome scroll anchoring
  4. google chrome scroll bar missing
  5. google chrome scroll to text
  6. google chrome scroll lag
  7. google chrome scroll through tabs
  8. google chrome scroll lock
  9. google chrome scroll wheel not working
  10. google chrome scroll bar not working
  11. google chrome scroll to text fragment
  12. google chrome scroll stutter
  13. google chrome scroll screenshot
  14. google chrome scroll bar too small
  15. google chrome scroll down problem
  16. google chrome scroll bar disappears
  17. google chrome scroll wheel zoom
  18. google chrome scroll tabs
  19. google chrome scroll settings
  20. google chrome scroll capture

I am not sure how to understand this foo property and array here. it looks like foo property got assigned to array, but I don't think it is even valid array syntax. Can someone explain the concept ...

I am not sure how to understand this foo property and array here. it looks like foo property got assigned to array, but I don't think it is even valid array syntax. Can someone explain the concept ...

I have a little issue that I couldn't figure out. I have a slider and I want to change url when I click prev and next buttons. Here are my codes below but it doesn't work correctly. Every time I click ...

I have a little issue that I couldn't figure out. I have a slider and I want to change url when I click prev and next buttons. Here are my codes below but it doesn't work correctly. Every time I click ...

  1. window location href new tab
  2. window location href relative
  3. window location href not working
  4. window location href vs replace
  5. window location href redirect
  6. window location href javascript
  7. window location href angular
  8. window location href react
  9. window location href mdn
  10. window location href vs assign
  11. window location href jquery
  12. window location href target _blank javascript
  13. window location href in php
  14. window location href reload
  15. window location href is not a function
  16. window location href html
  17. window location href post
  18. window location href encode url
  19. window location href with headers
  20. window location href back