promise的封装

来源:互联网 发布:sqlserver 回滚数据 编辑:程序博客网 时间:2024/06/05 00:09

function ajax(url){
return new Promise(function(resolve,reject){
var xhr=new XMLHttpRequest();
xhr.open("GET",url);
xhr.send();
xhr.onload=resolve;
xhr.onerror=reject;
})
}
ajax("http://baidu.com").then(function(data){
console.log(data)
},function(){

})
0 0
原创粉丝点击