//jq提供ajax请求
// $.ajax({
// type: "get",
// url: "",
// data: {},
// dataType: "json",
// success: function (data) {
// }
// })
let $ = {};
$.__proto__.ajax = function({type='get',url,data,dataType='HTML',success}){
let xhr = new XMLHttpRequest();
if(type === 'get' || type === 'GET'){
xhr.open(type,data?`${url}?${data}`:url);
xhr.send(null)
}else if(type === 'post' || type === 'POST'){
xhr.open(type,url);
xhr.send(data)
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
}
xhr.onreadystatechange = function(){
if(xhr.readyState === 4 && xhr.status === 200){
if(dataType === 'HTML'){
success(xhr.responseText)
}else if(dataType === 'JSON'){
success(JSON.parse(xhr.responseText))
}
}
}
}
console