Nodejs, How do I wait until the previous post request is completed. Below is the Snippet:
var data ="xxxx"
let XMLHttpRequest1 = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest1();
xhr.withCredentials = true;
xhr.open("POST", https://corpqa.sts.xxxx.com/adfs/oauth2/token);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
console.log("Execution Order 1");
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log("Execution Order 2");
//console.log(this.responseText);
}
});
console.log("Execution Order 3");
In NodeJS, below is the Output of the above code:
Execution Order 1
Execution Order 3
Execution Order 2
How do I make code to WAIT for response, execute this.readyState ===4. before it proceed to execute console.log("Execution Order 3").
Expected Output
Execution Order 1
Execution Order 2
Execution Order 3