<commit_before>var Ajax = {
    /**
     * ajax 封装
     * @param  options {
     *             type: GET || POST
     *             datatype: JSON as default
     *             url: Interface URL
     *             sdata:
     *             callback: Callback function
     *             async: true || false 
     *         }
     */
    ajax: function(options) {
        /* 参数列表 */
        var         type = options.type         || 'GET',
                datatype = options.datatype     || 'JSON',
                     url = options.url          || '',
                   sdata = options.sdata        || null,
           beforeRequest = options.beforRequest || function() {},
                callback = options.callback     || function() {},
                   fdata = options.fdata        || null,
                   async = options.async        || true;
 
        var W = Ajax.createXMLHttpRequest();
 
        W.onreadystatechange = function() {
            if(async) {
                Ajax.callbackFunction(datatype, W, callback, fdata, Ajax);
            }
        };
        /* 初始化HTTP请求参数 */
        W.open(type, url, async);
 
        if(type === 'GET') {
            W.send(null);
        } else {
            //W.setRequestHeader('Content-length', sdata.length);
            W.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            W.send(sdata);
        }
 
        if(async) {
            return W;
        } else {
            Ajax.callbackFunction(datatype, W, callback, fdata, Ajax);
        }
    },
    /* 创建兼容的 XMLHttpRequest 对象 
     *
     */
    createXMLHttpRequest: function() {
        var temp;
 
        /* 兼容IE */
        try {
            temp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(E) {
            try {
                temp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch(E) {
                temp = new XMLHttpRequest();
            }
        }
 
        return temp;
    },
    /* 回调函数 */
    callbackFunction: function(type, req, callback, data, obj) {
        /* 请求完成，响应就绪 */
        if(req.readyState == 4 && req.status == 200) {
            var result = req.getResponseHeader('content-type'),
                ajaxData = !type && result && result.indexOf('xml') >= 0;
 
            ajaxData = type == 'xml' || ajaxData ? req.responseXML : req.responseData;
 
            if(type == 'JSON') {
                ajaxData = eval("(" + req.responseText +")");
            }
 
            if(req.status != 200) {
                
            } else {
                callback(ajaxData, data);
            }
        }
    }
};
 
/* 全局对象 */
window.Ajax = Ajax;<commit_msg>allow CORS(browser compatiable)<commit_after>var Ajax = {
    /**
     * ajax 封装
     * @param  options {
     *             type: GET || POST
     *             datatype: JSON as default
     *             url: Interface URL
     *             sdata:
     *             callback: Callback function
     *             async: true || false 
     *         }
     */
    ajax: function(options) {
        /* 参数列表 */
        var         type = options.type         || 'GET',
                datatype = options.datatype     || 'JSON',
                     url = options.url          || '',
                   sdata = options.sdata        || null,
           beforeRequest = options.beforRequest || function() {},
                callback = options.callback     || function() {},
                   fdata = options.fdata        || null,
                   async = options.async        || true;
 
        var W = Ajax.createXMLHttpRequest();
 
        W.onreadystatechange = function() {
            if(async) {
                Ajax.callbackFunction(datatype, W, callback, fdata, Ajax);
            }
        };
        /* 初始化HTTP请求参数 */
        W.open(type, url, async);

        // 允许跨域
        // (不能放在上面，会有浏览器兼容问题)
        W.withCredentials = true;

        if(type === 'GET') {
            W.send(null);
        } else {
            //W.setRequestHeader('Content-length', sdata.length);
            W.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            W.send(sdata);
        }
 
        if(async) {
            return W;
        } else {
            Ajax.callbackFunction(datatype, W, callback, fdata, Ajax);
        }
    },
    /* 创建兼容的 XMLHttpRequest 对象 
     *
     */
    createXMLHttpRequest: function() {
        var temp;
 
        /* 兼容IE */
        try {
            temp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(E) {
            try {
                temp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch(E) {
                temp = new XMLHttpRequest();
            }
        }
 
        return temp;
    },
    /* 回调函数 */
    callbackFunction: function(type, req, callback, data, obj) {
        /* 请求完成，响应就绪 */
        if(req.readyState == 4 && req.status == 200) {
            var result = req.getResponseHeader('content-type'),
                ajaxData = !type && result && result.indexOf('xml') >= 0;
 
            ajaxData = type == 'xml' || ajaxData ? req.responseXML : req.responseData;
 
            if(type == 'JSON') {
                ajaxData = eval("(" + req.responseText +")");
            }
 
            if(req.status != 200) {
                
            } else {
                callback(ajaxData, data);
            }
        }
    }
};
 
/* 全局对象 */
window.Ajax = Ajax;
{'fraction_non_alphanumeric': 0.1288298265042451, 'fraction_numerical': 0.0033222591362126247, 'mean_word_length': 1.2218122181221813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '286366', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1540, 'n_words': 295}