jeudi 11 mai 2017

Wait for asynchronous GETs to complete in What Javascript/JQuery

I'm fully aware that async: false is deprecated with XMLHttpRequest, but the following code meets my immediate need to GET all pages before a subsequent task iterates over them.

for (i=0; i <= last_page; i++) {
  $.ajax({
      url : '/static/experiments/zoning_out_task/text/' + i + '.html',
      cache: false,
      async: false,
      success : function(result) {
          pages.push(result);
      }
  });

}

Is there a pattern that achieves the same thing using async: true?

Aucun commentaire:

Enregistrer un commentaire