Skip to content

Instantly share code, notes, and snippets.

@onur-km
Forked from deanhume/XHR-request.js
Created April 6, 2021 11:48
Show Gist options
  • Save onur-km/c8408eb4142562e61dff3d6b997c6a7d to your computer and use it in GitHub Desktop.
Save onur-km/c8408eb4142562e61dff3d6b997c6a7d to your computer and use it in GitHub Desktop.
A simple XHR request
function successListener() {
var data = JSON.parse(this.responseText);
console.log(data);
}
function failureListener(err) {
console.log('Request failed', err);
}
var request = new XMLHttpRequest();
request.onload = successListener;
request.onerror = failureListener;
request.open('get', './api/some.json', true);
request.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment