Sha256: b5accc373174fd3aca29d812ee7c87699bb17344d5876c149484b517ae017385

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

/**
 * ajax
 * Utility to perform ajax get and post requests. Supported browsers: 
 * Chrome, Firefox, Opera, Safari, Internet Explorer 7+.
 */
var ajax = (function () {
    function fetch (method, url, body, headers, callback) {
        try {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
                if (xhr.readyState == 4) {
                    callback(xhr.responseText, xhr.status);
                }
            };
            xhr.open(method, url, true);
            if (headers) {
                for (var name in headers) {
                    if (headers.hasOwnProperty(name)) {
                        xhr.setRequestHeader(name, headers[name]);
                    }
                }
            }
            xhr.send(body);
        }
        catch (err) {
            callback(err, 0);
        }
    }

    function get (url, headers, callback) {
        fetch('GET', url, null, headers, callback);
    }

    function post (url, body, headers, callback) {
        fetch('POST', url, body, headers, callback)
    }

    return {
        'fetch': fetch,
        'get': get,
        'post': post
    }
})();

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bee_api-0.0.5 vendor/app/web/ajax.js