JSFiddle - React, Tailwind, and code Playground
by Joseph Tate
JavaScript
function foo(callback) {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === 4) { // request is done
if (httpRequest.status === 200) { // successfully
callback(httpRequest.responseText); // we're calling our method
}
}
};
httpRequest.open('GET', "/echo/json");
httpRequest.send();
}
foo(function (result) {
document.body.innerHTML = result;
});