//1.创建处理客户传递数据的函数
function resolveData(data) {
var arr=[]
for (let k in data){
var str = k + '='+data[k]
arr.push(str)
}
return arr.join('&')
}
//2.封装处理函数
function itheima(options) {
var xhr = new XMLHttpRequest ()
var qs = resolveData(options.data) //查询参数
if(options.method.toUpperCase()=== 'GET'){ //判断提交类型
xhr.open(options.method,option.url+'?'+qs)
xhr.send()
}
else if(options.method.toUpperCase()==='post'){
xhr.open(options.method,options.url)
xhr.setRequestHeader('Conten-Type','application/x-www-form-urlencoded')
xhr.send(qs)
}
xhr.onreadystatechange = function () {
if(xhr.readystate === 4 && xhr.status === 200){
let result = JSON.parse(xhr.responseText)
options.success(result)
}
}
}