<commit_before>function ajax(params){
    var xhr = new (self.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP");  //最简实现xhr
	if(!xhr){
		return false;
	}
	var options = {
		url: params.url||'',
		method: (params.method||'GET').toUpperCase(),
		timeout: params.timeout||5000,
		async : true,
		complete: params.complete||function(){},
		error: params.error||function() {},
		success: params.success||function(){},
		type: params.type||'json',
		data: params.data||{}
	};	
	var json2string = function(json) {
        var arr = [];
        for(var i in json) {
            arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(json[i]));    
        }
        return arr.join("&");
    };
	options.data = json2string(options.data);
	xhr.open(options.method, options.url, options.async);
	if (options.method == 'GET') {
		xhr.send(null);
	}else{
		xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
		xhr.send(options.data);
	}
	var requestDone = false;
	setTimeout(function() {
		requestDone = true;
		if(xhr.readyState != 4){
			xhr.abort();
		}
	}, options.timeout);
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4&&!requestDone) {
			if(xhr.status == 200) {
				var data = options.type == "xml" ? xhr.responseXML : xhr.responseText;
				if (options.type == "json") {
					try{
						data =  JSON.parse(data);
					}catch(e){
						data = eval('(' + data + ')');
					}
				}
				options.success(data);
			} else {
				options.error();
			}
			options.complete();
		}
	};
}
<commit_msg>updated 添加报错提示及兼容<commit_after>function ajax(params){
    var xhr = new (self.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP"); //最简实现xhr
	if(!xhr){
		return false;
	}
	params = params||{};
	if (!params.url || !params.callback) {
        throw new Error('Necessary parameters are missing'); //必要参数未填
    }
	var options = {
		url: params.url||'',
		method: (params.method||'GET').toUpperCase(),
		timeout: params.timeout||5000,
		async : true,
		complete: params.complete||function(){},
		error: params.error||function() {},
		success: params.success||function(){},
		type: params.type||'json',
		data: params.data||{}
	};	
	var json2string = function(json) {
        var arr = [];
        for(var i in json) {
            arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(json[i]));    
        }
        return arr.join("&");
    };
	options.data = json2string(options.data);
	xhr.open(options.method, options.url, options.async);
	if (options.method == 'GET') {
		xhr.send(null);
	}else{
		xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
		xhr.send(options.data);
	}
	var requestDone = false;
	setTimeout(function() {
		requestDone = true;
		if(xhr.readyState != 4){
			xhr.abort();
		}
	}, options.timeout);
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4&&!requestDone) {
			if(xhr.status == 200) {
				var data = options.type == "xml" ? xhr.responseXML : xhr.responseText;
				if (options.type == "json") {
					try{
						data =  JSON.parse(data);
					}catch(e){
						data = eval('(' + data + ')');
					}
				}
				options.success(data);
			} else {
				options.error();
			}
			options.complete();
		}
	};
}

{'fraction_non_alphanumeric': 0.18662081900593935, 'fraction_numerical': 0.006877149109096593, 'mean_word_length': 3.249667994687915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '2378043', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1146, 'n_words': 195}