This question has already been answered:
How can I get the file contents or server response to a global variable? In the following function, the global variable after the function remains undefined , whereas if you call alert inside the function, the value is assigned to it.
I need to read a few files and send to the service API with a half dozen requests, and then digest it all. If you do the ladder, then in this ladder, I drown. I would like to get the variable out of the function. Is it possible
<script> var myVar; $.get("example.html", function(data) { myVar = data; alert(myVar); // всё отлично }, "html"); alert(myVar); // undefined </script>