I have the following structure of 2 functions -
function myfunc(param1, param2){
//some stuff happens
//some stuff happens
let request = new XMLHttpRequest();
request.open("POST",documentumUploadAPI);
request.setRequestHeader('Authorization', 'Bearer ' + token);
request.setRequestHeader('Content-Type', 'multipart/form-data');
request.send(formData);
var flag = false;
var flag1 = 'not successful';
request.onreadystatechange = function() {
if (request.readyState === 4) {
flag = request.responseText.includes('"success" : true');
if(flag){
flag1 = 'successful';
}
}
}
}
Now i want to return the value of flag1 and use it but since the scope of the variable is limited to the function only, i cannot get the value of flag1 as 'successful'. Is there any way to return the value of flag1 being changed in the onreadystatechange function?