<commit_before>goog.provide('og.Ajax');

og.Ajax = {
    ReadyState:
    {
        Uninitialized: 0,
        Loading: 1,
        Loaded: 2,
        Interactive: 3,
        Complete: 4
    },
    Status:
    {
        OK: 200,
        Created: 201,
        Accepted: 202,
        NoContent: 204,
        BadRequest: 400,
        Forbidden: 403,
        NotFound: 404,
        Gone: 410,
        ServerError: 500
    },
    Method: { Get: "GET", Post: "POST" },
    Asynchronous: true,
    Synchronous: false
};


og.Ajax.defaultParams = { type: og.Ajax.Method.Get, async: og.Ajax.Asynchronous, data: null, sender: null, responseType: "text" };

og.Ajax.createXMLHttp = function () {
    var xhr = null;
    if (typeof (XMLHttpRequest) != undefined) {
        xhr = new XMLHttpRequest;
        return xhr;
    } else if (window.ActiveXObject) {
        var ieXMLHttpVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
        for (var i = 0; i < ieXMLHttpVersions.length; i++) {
            try {
                xhr = new ActiveXObject(ieXMLHttpVersions[i]);
                return xhr;
            } catch (e) {
            }
        }
    }
};

og.Ajax.request = function (url, params) {
    var p;

    if (params)
        p = params;
    else
        p = og.Ajax.defaultParams;
    
    var xhr = og.Ajax.createXMLHttp();
    xhr.open(p.type ? p.type : og.Ajax.defaultParams.type, url, p.async);
    if (p.type === og.Ajax.Method.Post) {
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    }
    xhr.responseType = p.responseType ? p.responseType : og.Ajax.defaultParams.responseType;
    xhr.onreadystatechange = function () {
        if (xhr.readyState === og.Ajax.ReadyState.Complete) {
            if (xhr.status === og.Ajax.Status.OK) {
                params.success.call(p.sender ? p.sender : this, xhr.response);
            } else {
                params.error.call(p.sender ? p.sender : this, xhr.response, xhr.status);
            }
        } else {
            //still loading
        }
    };
    xhr.send(p.data ? p.data : og.Ajax.defaultParams.data);
};<commit_msg>Safety ajax requests.<commit_after>goog.provide('og.Ajax');

og.Ajax = {
    ReadyState:
    {
        Uninitialized: 0,
        Loading: 1,
        Loaded: 2,
        Interactive: 3,
        Complete: 4
    },
    Status:
    {
        OK: 200,
        Created: 201,
        Accepted: 202,
        NoContent: 204,
        BadRequest: 400,
        Forbidden: 403,
        NotFound: 404,
        Gone: 410,
        ServerError: 500
    },
    Method: { Get: "GET", Post: "POST" },
    Asynchronous: true,
    Synchronous: false
};


og.Ajax.defaultParams = { type: og.Ajax.Method.Get, async: og.Ajax.Asynchronous, data: null, sender: null, responseType: "text" };

og.Ajax.createXMLHttp = function () {
    var xhr = null;
    if (typeof (XMLHttpRequest) != undefined) {
        xhr = new XMLHttpRequest;
        return xhr;
    } else if (window.ActiveXObject) {
        var ieXMLHttpVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
        for (var i = 0; i < ieXMLHttpVersions.length; i++) {
            try {
                xhr = new ActiveXObject(ieXMLHttpVersions[i]);
                return xhr;
            } catch (e) {
            }
        }
    }
};

og.Ajax.request = function (url, params) {
    var p = og.Ajax.defaultParams;

    for (var i in params)
        p[i] = params[i];

    var xhr = og.Ajax.createXMLHttp();
    xhr.open(p.type, url, p.async);
    if (p.type === og.Ajax.Method.Post) {
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    }
    if (p.async)
        xhr.responseType = p.responseType;

    xhr.overrideMimeType("text/plain");
    xhr.onreadystatechange = function () {
        if (xhr.readyState === og.Ajax.ReadyState.Complete) {
            if (xhr.status === og.Ajax.Status.OK) {
                if (params.success)
                    params.success.call(p.sender ? p.sender : this, xhr.response);
            } else {
                if (params.error)
                    params.error.call(p.sender ? p.sender : this, xhr.response, xhr.status);
            }
        } else {
            //still loading
        }
    };
    xhr.send(p.data ? p.data : og.Ajax.defaultParams.data);
};
{'fraction_non_alphanumeric': 0.14078768673607966, 'fraction_numerical': 0.019465821638750568, 'mean_word_length': 1.8807040417209908, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1403497', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1486, 'n_words': 296}