const formsParams = (data) => {
var arr = []
for(var prop in data){
arr.push(prop + "=" + data[prop])
}
return arr.join("&")
}
const ajax = async(options) => {
let xhr = null;
let { type, url, async = true, data } = options
type = type.toUpperCase()
let params = formsParams(data);
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest()
} else {
xhr = new ActiveXObject("Microsoft.XMLHTTP")
}
if(type == "GET"){
xhr.open(type, url + "?" + params, async)
xhr.send(null)
} else if(type == "POST"){
xhr.open(type, url, async)
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
xhr.send(params)
}
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
options.success(xhr.responseText)
}
}
}
console