function ajax(method,url,callback,data){
let xhr = new XMLHttpRequest() || new ActiveXObject(‘Microsoft.XMLHTTP‘)
xhr.open(method,url,true)
if(method === ‘get‘){
xhr.send()
}
if(method===‘post‘){
xhr.setRequestHeader(‘Content-Type‘,‘application/json‘)
xhr.send(JSON.stringify(data))
}
xhr.onreadystatechange = function(){
if(this.readyState === 4 && this.status === 200){
callback(JSON.parse(this.responseText))
}
}
}