0

I want to loop through a list and make an API-request for each value. I want the request to be made synchronously, so the 2nd request should start when the first finished. However i want them to be async so UI does not freeze.

How can do i do that with an each loop and an ajax request:

     $.each(resultList, function (i, e) {
     $.ajax({
                type: 'GET',
                data: {
                    _rnd: new Date().getTime()
                },
                url: saveResultUrl + '?data=' + e,
                dataType: 'json',
                async: true,
            })
});
Lord Vermillion
  • 5,264
  • 20
  • 69
  • 109
  • instead of `async: true`, set `async: false`, – IsraGab Feb 15 '16 at 14:24
  • 1
    "I want the request to be made synchronously, so the 2nd request should start when the first finished. However i want them to be async so UI does not freeze." — These two statements are contradictory. – Quentin Feb 15 '16 at 14:24
  • I could nest multiple async requests in the success: function() {}, however im not sure how to do this with a loop, – Lord Vermillion Feb 15 '16 at 14:26
  • @Quentin is right, you can't do an ajax call synchronise **and** a-synchronise. If you have to wait for the server response you have to make synchronise call – IsraGab Feb 15 '16 at 14:27

0 Answers0