function ajax(obj){
var str = "";
for(var key in obj.data){
str += key +"="+obj.data[key]+"&";
}
str = str.substring(0,str.length-1);
var xhr = null;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else{
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
if(obj.type.toUpperCase() == "GET"){
if(obj.data){
var url = obj.url+"?"+str;
}else{
var url = obj.url;
}
xhr.open("get",url,true);
xhr.send(null);
}
if(obj.type.toUpperCase() == "POST"){
xhr.open("post",obj.url,true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(str);
}
xhr.onreadystatechange=function(){
if(xhr.readyState == 4){
if(xhr.status == 200){
var data = xhr.responseText;
obj.success(data);
}
}
}
}