I have a myurl.txt e.g containing
{'name':'myname','age':23}
How to do a function
function getRequest() {
var result = {};
(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
result = JSON.parse(xmlhttp.responseText);
};
xmlhttp.open("GET", "myurl.txt", true);
xmlhttp.send();
})();
return result;
}
console.log(1);
console.log(getRequest());
console.log(2);
that i can get the result, that it do the function onreadystatechange as the last thing (without a jQuery). And write to a console
1
{'name':'myname','age':23}
2
Thank you.