can you help me with this code snippet? In this part, I make a ajax request to my c# controller only to validate a email and get the boolean value, but in the process, a promise returns status pending make a problem because i really need only the value inside the promise, here my code:
let Email = input;
let valida = ValidaEmail(Email);
console.log(valida);
The Function
async function ValidaEmail(email) {
let promise = new Promise(resolve => {
var string = JSON.stringify(email);
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/Home/EmailisValid", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.onreadystatechange = () => {
if (xhttp.readyState === 4 && xhttp.status === 200)
resolve(xhttp.response);
};
xhttp.send(string);
});
let retorno = await promise;
console.log(retorno);
}
The Output: