function ajax ({type, url, data, callback}){
var xhr = window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP') if(typeof data === 'object'){ var arr = [] for( var prop in data){ arr.push(prop +'='+ data[prop]) } data = arr.join('&') } if(type === "GET"){ xhr.open(type, url +'?'+ data) xhr.send() }else if (type === 'POST'){xhr.open(type,url) xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') xhr.send(data) } xhr.onreadystatuschange = function () { if(this.readyStatus === 4){ if(this.status === 200){ callback&& callback(this.responseText) } } }