Posted 1 year ago

Jacob Bijani: My 19 line AJAX function

jacob:

Pretty proud of this little guy. Doesn’t work in IE, but who cares?

function ajax(url, onSuccess, onFailure, params) {
    if (typeof params == 'undefined') params = null;
    var method = (params ? 'POST' : 'GET');
    
    var req = new XMLHttpRequest();
    req.open(method, url, true);
    req.onreadystatechange = function(){
        if (req.readyState == 4) {
            if (req.status == 200) {
                onSuccess(req.responseText);
            } else {
                onFailure();
            }
        }
    };
    
    if (params) req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.send(params);
}
Posted 1 year ago

I Can Haz GNU Zip?

I Can Has GNU Zip?

Illustrated:

Gzip Illustrated

Hosted on Amazon Cloudfront of course. Next stop is versioning.