JSFiddle - React, Tailwind, and code Playground
JavaScript
(function() {
var running = {};
function noop() {}
function handler() {
if (this.readyState === 4) {
(running[this.id][this.status === 200 ? "onsuccess" : "onerror"] || noop).call(this);
delete running[this.id];
}
}
window.send = function(url, method, data, onsuccess, onerror) {
var req = new XMLHttpRequest();
req.open(method, url, true);
req.onreadystatechange = handler;
req.send(data);
req.id = (Math.random() * 1e5 | 0).toString(32);
running[req.id] = {
"onsuccess": onsuccess,
"onerror": onerror
};
}
})();
send("/echo/html/", "POST", "html=World!", function(){ alert("Hello, " + this.responseText) });