Answer the question
In order to leave comments, you need to log in
How to return a variable from xhr.onload event?
Hey!
Why can't I get the value of a variable outside of a function?
First I set a variable, then in the body of the function I assign a value to this variable and make a closure. But for some reason the result is not returned. Maybe it has something to do with Ajax? For with cycles and other constructions, this method rolls.
What's the matter?
Answer the question
In order to leave comments, you need to log in
This is an asynchronous event. At the moment when you do console.log() the result of the request has not yet come.
And don't make the code a picture anymore.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question