原生ajax封装成promise
var myNewAjax = function(url){ return new Promise(function(resolve,reject){ var xhr = new XMLHttpRequest() xhr.open('get',url) xhr.send(data) xhr.onreadystatechange = function(){ if(xhr.readyState === 4 && xhr.status === 200){ var json = JSON.parse(xhr.responseText) resolve(json) } else if(xhr.readyState === 4 && xhr.status !== 200){ reject('error') } } }) }
前端问题总结 文章被收录于专栏
总结一些前端常见的面试笔试题,来和大家分享鸭