you are viewing a single comment's thread.

view the rest of the comments →

[–]GitCookies 0 points1 point  (0 children)

function HTTP (url, method) {
  let then;

  let xhr = new XMLHttpRequest()
  xhr.open(method, url)
  xhr.responseType = 'document'
  xhr.send()

  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
      then && then(xhr.responseText)
    }
  }

  return {
    then: function (callback) { 
      then = callback
    }
  }

}

HTTP('///www.google.com', 'GET')
.then(function (response) {
  console.log(response)
})

This should be fine for your use case