I want my <script>
not to continue running until I get the server's response and do what it has to do, I'm using native browser Javascript, that is, without frameworks or libraries or anything.
<script>
function run(){
cargar()
sppWizard.init(optionsAssistant);
}
</script>
</head>
<body class="spp-loading" onload="run()">
Here in the Head, I create the load () function; WHEN I have finished that function I want the next line to be executed.
function cargar() {
// realizamos proceso de validacion del JSON
var request = new XMLHttpRequest();
request.open("GET", "./entrada", true);
request.send(null);
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status === 200) {
var MyJSON = JSON.parse(request.responseText);
procesar(MyJSON);
}
}
}
In turn this function will call others and so, but when the Load () ends; is when the javascript code should follow, how do I do this?
At the moment the JSON of the server, I take it from the premises, in the future, a server will be called ...
Thank you.