function ajax(method,url,data,success){
try{
var xhr=new XMLHttpRequest();
}catch(e){
xhr=new ActiveXObject(‘Mocrosoft.XMLHTTP‘);
}
if(method==‘get‘&&data){
url+=‘?‘+data;
}
xhr.open(method,url,true);
if(method==‘get‘){
xhr.send();
}else{
xhr.setRequestHeader(‘Content-type‘, ‘application/x-www-form-urlencoded‘);
xhr.send(data);
}
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
success&&success(xhr.responseText);
//console.log(xhr.responseText);
}
}
}