I have function, that sends request to create encrypted cookie. Inside that function there is onload function.
What I need?
I need to "transfer" return from onload() to parent function.
function createCookie(method = "POST", action, parameters, token, contentType = "application/x-www-form-urlencoded") {
let xhr = new XMLHttpRequest();
xhr.open(method, action, true);
xhr.setRequestHeader('Content-type', contentType);
xhr.onload = () => {
let jsonResponse = JSON.parse(xhr.responseText);
if(jsonResponse && jsonResponse['status'] == 'true') {
return true;
} else {
return false;
}
}
xhr.send("_token=" + token + "&" + parameters);
}