2
I want to make an indefinite number of ajax requests, according to the number of urls passed as parameter, I just need to know how to increment the (name) of the variable so that the answer does not overlap with the previous one.
Each request will fetch a different html content or json object and insert them into different elements of the document, without changing the variable all elements are incremented with the last loop response. Obs, putting the third argument 'false', in the open() method; right, but gives an alert in the console saying that it is not a good practice
[Deprecation] Synchronous Xmlhttprequest on the main thread is deprecated because of its detrimental effects to the end user’s Experience.
Example of what I’m looking for:
With each iteration I want the variable name to change:
var a = new XHtmlHTTPrequest();
In the next iteration:
var b = new XHtmlHTTPrequest();
callback and asynchronous is always a good way +1. PS: Congratulations on 100k, synonymous with commitment, the community just has to thank you.
– Guilherme Nascimento
@Thank you Guilhermenascimento! And you walk there too :)
– Sergio
-1 for not using Yoda Conditions with Star Wars API :D
– bfavaretto
@bfavaretto haha :)
– Sergio
I had not tried with callback yet, in fact the scope of the function will isolate the variable and solve my problem. however the doubt remains it is possible to auto increment the name of a variable?
– Rodrigo A. Santos
@Rodrigoa.Santos you can, but it’s not the best solution. You can create an object and then go on doing
obj['div-' + i] = algo...
, but in this case it is not so useful.– Sergio
@Rodrigoa.Santos could even use one
Map
(new technology) that accepts as key the DOM element itself.– Sergio
Too bad the Star Wars API doesn’t have images!!
– Sergio