Skip to content

Instantly share code, notes, and snippets.

@brettvaida
Created November 25, 2017 20:00
Show Gist options
  • Select an option

  • Save brettvaida/542e6faedb89f91b05411f34f1ff9778 to your computer and use it in GitHub Desktop.

Select an option

Save brettvaida/542e6faedb89f91b05411f34f1ff9778 to your computer and use it in GitHub Desktop.
AJAX POST request boilderplate
const xhr = new XMLHttpRequest;
const url = 'https://api-to-call.com/endpoint';
const data = JSON.stringify({id: '200'});
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
console.log(xhr.response);
}
};
xhr.open('POST', url);
xhr.send(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment