JSFiddle - React, Tailwind, and code Playground
by Scott Kaye
JavaScript
console.clear();
(function () {
var open = XMLHttpRequest.prototype.open;
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
if (url == "/echo/html") {
this.cachedData = "test data";
var ready = this.onreadystatechange;
this.onreadystatechange = function () {
if (this.readyState == 1) {
delete this.responseText;
this.responseText = this.cachedData;
return ready.call(this);
} else {
return ready.apply(this, arguments);
}
}
}
return open.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function (data) {
if (!this.cachedData) send.call(this, data);
};
})();
//Tests
var x = new XMLHttpRequest();
x.onreadystatechange = function () {
console.log("onreadystatechange:", x.response, x);
};
x.open("GET", "/echo/html", true);
x.send();