Looking to make multiple ajax requests and return the data one by one in a for loop. However, sometimes new data is sent before the previous request is completed, resulting in incorrect data being returned. This doesn't happen often, but I need help solving this issue.
for (var i=0; i<myarray.length;i++){
ajaxfunction(myarray[i]);
}
I've tried using setTimeout in the loop, but the results were incorrect.
I prefer using pure javascript, no JQuery or other library. I came across "complete:" and ".done()" in JQuery, but I'm not sure if they're what I need. Can someone guide me on how to solve this problem with raw javascript?