JSFiddle - React, Tailwind, and code Playground

by ammarcse

HTML

<script src="https://dl.dropboxusercontent.com/u/7909102/log.js"></script>

JavaScript

(function(proxied) {
    XMLHttpRequest = function() {
        //cannot use apply directly since we want a 'new' version
        var wrapped = new(Function.prototype.bind.apply(proxied, arguments));

        Object.defineProperty(wrapped, 'responseText', {
            writable: true
        });

        return wrapped;
    };
})(XMLHttpRequest);

// my own little plain javascript ajax function
function ajax(url, data, fn) {
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
        this.responseText = '{"msg": "Hello"}';
        if (this.readyState == 4) {
            fn(this);
        }
    }
    request.open("POST", url, true);
    request.send(data);
}

var x = {
    myData: 1
};

ajax("/echo/json/", "json=" + encodeURIComponent(JSON.stringify(x)) + "&delay=1", function(req) {
    log("modified ajax response" + req.responseText);
});