Skip to content

Instantly share code, notes, and snippets.

@sskoopa
Created November 17, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sskoopa/b9c801cd7b0502665d14ad6b2c65c86b to your computer and use it in GitHub Desktop.
Save sskoopa/b9c801cd7b0502665d14ad6b2c65c86b to your computer and use it in GitHub Desktop.
Simple XHR to use like fetch in REST APIs
var oReq = new XMLHttpRequest()
oReq.onload = function (e) {
var xhr = e.target
if (xhr.status === 200 && onSuccess) {
onSuccess(xhr.response)
} else if (xhr.status !== 200 && onFailure) {
onFailure(xhr.response)
}
}
oReq.open(method, action, true)
oReq.setRequestHeader('Content-Type', 'application/json')
oReq.responseType = 'json'
oReq.send(JSON.stringify(formdata))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment