Created
April 24, 2018 14:44
-
-
Save chongiscool/227bdee50be6712aba6bb6f0a22c6168 to your computer and use it in GitHub Desktop.
JS 'POST' request template from codecademy.
This file contains 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 url = 'https://www.googleapis.com/urlshortener/v1/url'; | |
const apiKey = 'AIzaSyB_gg7APX8yD_jzBHmTGxxDkhva95Zw808'; | |
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