var response_var=""; // Added for debugging purposes
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 & ajax.status == 200) {
response_var = ajax.responseText;
alert(ajax.responseText); // This alerts properly (some text).
return ajax.responseText; // This is returning as undefined
}
}
return response_var; // This is empty if I add line 1, if not in console it gives error response_var is not defined.
Why isn't the response being stored in the variable or returned? It seems like the scope of response_var
ends within the onreadystatechange
function so I tried using return
. However, the value remains undefined.