Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class AsyncRequest {
- sendRequest(method, url, param) {
- return new Promise(function (resolve, reject) {
- let xhr = new XMLHttpRequest()
- xhr.open(method, url)
- xhr.onload = function () {
- if (this.status >= 200 && this.status < 300) {
- resolve(xhr.response)
- } else {
- reject({
- status: this.status,
- statusText: xhr.statusText
- })
- }
- };
- xhr.onerror = function () {
- reject({
- status: this.status,
- statusText: xhr.statusText
- })
- }
- console.log(param)
- if (param == null) {
- xhr.send()
- } else {
- xhr.send(param)
- }
- }
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement