We already know that ajax is asynchronous and the only way to make it synchronous is to put the option async: false
.
what i want to do is something like this
for (var fact in facturas ) {
sendEmailAJAX(facturas[fact]);
console.log(fact+ "enviado!!!");
}
I want you to call sendEmailAJAX
one at a time and not all at once.
I can do it with async:false
but the browser crashes.
I can't figure out how to solve this problem.
you could set a time for the code that is in your to be executed again
for
, something like this:where 5000 specifies 5 seconds to wait to send the next one and you can modify it to your liking depending on the time used for each operation.
UPDATE 1
For more information consult the documentation of $.when() in the official page of jquery