in order to recover data from server I use XMLHttpRequest and my code is this (it works fine)
window.onload = function getArtists() {
xmlhttpLoad=new XMLHttpRequest();
xmlhttpLoad.onreadystatechange=function() {
if (xmlhttpLoad.readyState==4 && xmlhttpLoad.status==200) {
// put data in an invisible HTML elem
}
}
}
Now I want to use a particular library, but it requires that this data are loaded BEFORE document document.onload is fired. How can I do this? Can I use the code above but block HTML parsing until data are loaded? I mean something like
<head>
<script>
// block parsing until data are loaded
// put data from server in a variable
</script>
<script src="newLib.js"></script>
<head>
If you don’t use the
loadevent but just run the code directly, it will start immediately when the script block has been parsed.To make the parsing of the next block wait for the AJAX response, you have to make a synchronous request. You do that by supplying
falsefor the third parameter (async) in theopencall:}