i have here a simple code but at the moment i dont find the right way how to code it, can you tell me how i must code it that the function ReadCheck() give me the result from server and not just "undefined"
function Check()
{
var xhttp = new XMLHttpRequest();
var data = { nuser: "username", nemail: "email", };
xhttp.open("POST", "api/posts/check", true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.onreadystatechange = function()
{
if(this.readyState == 4 && this.status == 200)
{
return this.responseText;
}
}
xhttp.send(JSON.stringify(data));
}
function ReadCheck()
{
console.log(Check());
}