Skip to content Skip to sidebar Skip to footer

Two Ajax Calls Are Not Running Simultaneously

I have two ajax calls using jquery, The first one should take time around 20 seconds to be executed, but the second one is much faster, should be executed in Milliseconds. What is

Solution 1:

It's a race condition. You have this:

do_download: setting ajax call as async get_operation_status: setting ajax call as sync

so, the first function that you call is "get_operation_status", why?? Because do_download will be call when document will be ready but the other function will be call before, so, browser takes time to have the document ready, then first call is "get_operation_status" and this function freeze other calls because it's sync instead of async:

// tames some time, it's no inmediatelyjQuery(document).ready(function (e) {
    do_download();
});

// this call could be execute before do_downloadvar get_operation_status_interval = setInterval(get_operation_status, 1000);

Put both calls async (never never never SYNC) and the timer inside document ready as:

jQuery(document).ready(function (e) {
    do_download();
    var get_operation_status_interval = setInterval(get_operation_status, 1000);
});

Solution 2:

Your 2nd one is async: false. Change it to true.(or remove it completely)

Post a Comment for "Two Ajax Calls Are Not Running Simultaneously"