I am trying to import data with one ajax and trying to do live tracking of this imported data with another ajax to show progress bar(how many records have been uploaded).
checkPrgressVar = setInterval(checkPrgress, 1000);
importTaxes(importURL,cart_url,cart_token);
/* check progress of imported data */
function checkPrgress()
{
$.ajax({
url: $(document).find("input[name='progressURL']").val(),
type: 'POST',
dataType: 'json',
// showLoader: true,
data: "action=import_store",
complete: function(response) { debugger
var response = response.responseJSON.output;
},
error: function (xhr, status, errorThrown) {
console.log('Error happens. Try again.');
}
});
}
/* import data */
function importTaxes(importURL,cart_url,cart_token)
{
$.ajax({
url: importURL,
type: 'POST',
dataType: 'json',
showLoader: true,
data: "cart_url="+cart_url+"&cart_token="+cart_token+"&action=import_tax",
complete: function(response) { debugger
var response = response.responseJSON.output;
if(response.result == 'processing')
{
}
else
{
}
},
error: function (xhr, status, errorThrown) {
console.log('Error happens. Try again.');
}
});
}
My checkProgress ajax returns response only after getting response from importTax ajax while this checkProgress ajax should be independent of importProgress ajax.
However both ajax is calling different controllers, it seems magento is not allowing another controller to be called until it processed another one.
I don't know why it happens and how to resolve it ?
I have tried this link but not working.
Is it possible to fire multiple ajax requests asynchronously in Magento 2 backend?
EDIT1: what I have figured out that if I call another external URL instead of magento2 controller in checkProgress ajax call. it started working. It means magento2 is not allowing another controller to be execute while another is running via import ajax.
EDIT2- Both ajax started to work as expected if I change session storage from "files" to "db" in env.php file. It seems a session blocking issue as explained in below link-
Two simultaneous AJAX requests won't run in parallel
But use DB as session storage is not preferable. So If I use files as session storage still I don't know how to resolve it.
Have any one idea about it ?