function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var res = JSON.parse(this.responseText);
return res;
}
};
xhttp.open("POST", "Rest.php", true);
xhttp.send();
return xhttp.onreadystatechange();
}
console.log(loadDoc()); // undefined
function loadDoc() {
function success() {
console.log(JSON.parse(xhttp.responseText));
}
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "Rest.php", true);
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
return success();
}
};
xhttp.send();
}
loadDoc();
includeHTML - Include HTML DOM nodes/parts (loading) via HTML tag into HTML-page for templates and SPA (pure js)