JSFiddle - React, Tailwind, and code Playground
JavaScript
//Cross browser compatibility ///////////////////////////
var myRequest;
if (window.XMLHttpRequest) {
myRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
myRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
//My variable ///////////////////////////////////////////
var foo = "";
//Response handler //////////////////////////////////////
myRequest.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status === 200) {
foo = "New value:" + this.responseText;
} else {
alert('There was a problem with the request.');
}
}
};
//Send request //////////////////////////////////////////
myRequest.open('GET', "/");
myRequest.send();
//Alert updated variable ////////////////////////////////
alert(foo);