I understand what is going on here, i'm trying to assign the return value of a function to a variable, this is pretty straightforward, until you start working with asynchronous requests, i guess this is more a call for ideas rather than understanding what's going on
this will return undefined, i want a="ok";
Javascript:
var ajax = {
touch: function(url) {
var ajax = new XMLHttpRequest();
ajax.open('GET',url);
ajax.send();
ajax.onreadystatechange=function(){
if(this.readyState == 4 && this.status == 200) {
var response = this.responseText.toString();
return response;
}
};
},
}
var a = ajax.touch('session.php');
console.log(a);
session.php
<?php
echo "ok";
?>
already tried to set ajax to FALSE so it goes synchronous but that's deprecated