原生js写ajax结合promise对象
2021-03-13 20:34
阅读:561
标签:end table eject xmlhttp pre highlight ons cell order
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
const ajaxPromise = param => {
return new Promise((resovle, reject) => {
var xhr = new XMLHttpRequest();
xhr.open(param.type || "get" , param.url, true );
xhr.send(param.data || null );
xhr.onreadystatechange = () => {
if (xhr.readyState === 4){
if (xhr.status === 200){
resovle(JSON.parse(xhr.responseText));
} else {
reject(JSON.parse(xhr.responseText));
}
}
}
})
} |
原生js写ajax结合promise对象
标签:end table eject xmlhttp pre highlight ons cell order
原文地址:https://www.cnblogs.com/firework-hy/p/12817211.html
评论
亲,登录后才可以留言!