ajax类库
function ajax(value){
var url = value.url;
var type = value.type || "get";
var data = value.data || "";
var success = value.success;
var error = value.error || false;
//1、创建AJAX对象
var oAjax;
try{
//Firefox,Opera 8.0+, Safari
oAjax = new XMLHttpRequest();
}catch(e){
//Internet Explorer
try{
oAjax = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
oAjax = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("浏览器不支持ajax");
return false;
}
}
}
//链接服务器
oAjax.open(type, url, true);
//发送请求
oAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
oAjax.send(data);
//数据接收
oAjax.onreadystatechange = function(){
if(oAjax.readyState == 4){
if(oAjax.stack == 200){
var data = oAjax.responseText;
success(data);
}else{
if(error){
error();
}
}
}
}
}