39 lines
970 B
JavaScript
39 lines
970 B
JavaScript
class HTTP {
|
|
|
|
constructor() {
|
|
this.xhr = new XMLHttpRequest();
|
|
}
|
|
|
|
get(option) {
|
|
return new Promise((success, error) => {
|
|
var GetParams = ""
|
|
for (const key in option.data) {
|
|
GetParams += `&${key}=${option.data[key]}`
|
|
}
|
|
GetParams = GetParams.replace("&", "?")
|
|
option.url += GetParams;
|
|
|
|
this.xhr.open("GET", config.checkUrl() + option.url)
|
|
this.xhr.send()
|
|
this.onreadystatechange(success, error)
|
|
})
|
|
}
|
|
|
|
post() { }
|
|
|
|
onreadystatechange(success, error) {
|
|
this.xhr.onreadystatechange = () => {
|
|
if (this.xhr.readyState == 4) {
|
|
if (this.xhr.status == 200) {
|
|
success(JSON.parse(this.xhr.responseText));
|
|
} else {
|
|
console.log("暂无数据");
|
|
error(this.xhr)
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} |