封装代码:
function ajax({
url,type,data,dataType}){
return new Promise(function(open,err){
//1. 创建xhr对象
var xhr=new XMLHttpRequest();
//2.绑定监听事件
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var res=xhr.responseText;
if(dataType==="json")
res=JSON.parse(res)
open(res);
}
}
if(type=="get