Reputation: 97
I want to test asynchronous AJAX requests with jquery but it doesn't work as expected.
Here are my 3 requests :
idRpis.forEach(function(idRpi, index){
console.log("Start"+index+" : "+Date.now());
$.ajax({
type : 'POST',
url : AJAX,
dataType : 'json',
async : "true",
data : {
action : "test"
},
success : function(response) {
console.log("End"+index+" : "+Date.now());
}
});
});
The PHP file called looks like that :
//Pause for 3 seconds
session_start();
sleep(3);
The problem is that the 3 request are sent almost at the same time but arrive with a 3 seconds delay between each.
Is it not supposed to do the job in parallel and arrive at the same time ? That's what I would like to do.
Upvotes: 0
Views: 49
Reputation: 97
Thank's to @jeroen I found out that I was using "session_start()" and that locked the session so the requests had to wait until the previous has finished.
Upvotes: 2