Created
November 17, 2016 18:51
-
-
Save sskoopa/b9c801cd7b0502665d14ad6b2c65c86b to your computer and use it in GitHub Desktop.
Simple XHR to use like fetch in REST APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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