Created
November 25, 2017 20:00
-
-
Save brettvaida/542e6faedb89f91b05411f34f1ff9778 to your computer and use it in GitHub Desktop.
AJAX POST request boilderplate
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
| 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