How do you call the functions ? it would be great if you can post that code too and what is fn1(), you haven't explained what does it do ? If you post the code, that would help anyone who is looking at the code, understand the code pretty quickly.
PS: you should remove the client secret and key from the code. It's not a good idea to share those thing with code. Just a suggestion!
Thanks for your response and helping me on this. Apologize for all the confusion. Below is the simplified version of the same code which i have shared.
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");
Issue: How do i make code to WAIT for response and execute this.readyState ===4. before it proceed to execute console.log("Execution Order 3").
Currently, below is the output:
Execution Order 1
Execution Order 3
Execution Order 2
Could you please help me getting the output in below order:
Execution Order 1
Execution Order 2
Execution Order 3
putting the last console log inside the callback of addEventlistener, it means your console log would be inside the addEventlinstener but after the if statement
make the code that uses callback addEventListene a separate async method, simply use await on that method.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How do you call the functions ? it would be great if you can post that code too and what is fn1(), you haven't explained what does it do ? If you post the code, that would help anyone who is looking at the code, understand the code pretty quickly.
PS: you should remove the client secret and key from the code. It's not a good idea to share those thing with code. Just a suggestion!
Thanks for your response and helping me on this. Apologize for all the confusion. Below is the simplified version of the same code which i have shared.
Issue: How do i make code to WAIT for response and execute this.readyState ===4. before it proceed to execute console.log("Execution Order 3").
Currently, below is the output:
Could you please help me getting the output in below order:
Any help on this would be great!
There are two ways you can achieve this
putting the last console log inside the callback of addEventlistener, it means your console log would be inside the addEventlinstener but after the if statement
make the code that uses callback addEventListene a separate async method, simply use await on that method.