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));
}
}
}
})
}
|