Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. export default class AsyncRequest {
  2. sendRequest(method, url, param) {
  3. return new Promise(function (resolve, reject) {
  4. let xhr = new XMLHttpRequest()
  5. xhr.open(method, url)
  6. xhr.onload = function () {
  7. if (this.status >= 200 && this.status < 300) {
  8. resolve(xhr.response)
  9. } else {
  10. reject({
  11. status: this.status,
  12. statusText: xhr.statusText
  13. })
  14. }
  15. };
  16. xhr.onerror = function () {
  17. reject({
  18. status: this.status,
  19. statusText: xhr.statusText
  20. })
  21. }
  22. console.log(param)
  23. if (param == null) {
  24. xhr.send()
  25. } else {
  26. xhr.send(param)
  27. }
  28. }
  29. )
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement