V
V
Vitaly Vozhov2021-01-19 19:19:50
JavaScript
Vitaly Vozhov, 2021-01-19 19:19:50

Processing an API request in a loop?

How to access Itemlength variable outside of xhr.onload function in XMLHttpRequest request? So that I can use it in a loop to change the url parameters in this code:



Also in the Fetch request. How can the Itemlength be accessed outside of .then ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Yakimchuk, 2021-01-20
@yakimchuk-ry

There is no code, but in general, the cycles are synchronous, while the requests are not, therefore, while the cycle is running, without waiting for a response from the server, there is no way to get this data from the outside.
Therefore, chains of calls are made, i.e. expect a response, call another function with that response, and that function, in turn, can call other functions, including itself, to get a recursion (loop).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question