I have javascript that misses about 100 calls to a php script. The PHP script uses most of the memory and takes a few seconds, and then returns a json pass or fail response.
I don’t want the ajax calls to be asynchronous, since the server would stop interrupting using 100 instances of itself, so I tried using synchronous, the only problem is freezing the web page when it calls the script one call at a time .
How can I disable ajax calls one at a time and not freeze the page I'm on?
var a = [];
a[0] = 'test';
a[1] = 'hello';
a[2] = 'another';
$(document).ready(function(){
$.each(a, function(k,v) {
$.ajax({
url:'/this-script-takes-a-few-seconds-to-complete.php',
async:false,
data: {foo: v},
success: function(data){
console.log(data);
}
});
});
});
source
share