Created
May 7, 2015 07:07
-
-
Save kn9ts/d1f660d884dfe44c5be8 to your computer and use it in GitHub Desktop.
Making an ajax request using plain JavaScript
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
var data = { | |
ids: [12, 18, 27, 35, 41, 53, 66, 68, 72, 85, 94, 103, 111, 120, 133] | |
} | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function(xhr) { | |
if (xhr.readyState < 4 || xhr.status !== 200) { | |
return; | |
} | |
// all is well | |
if (xhr.readyState === 4) { | |
console.log(xhr.responseText); // the list of tweets | |
parseTweets(xhr.responseText) | |
} | |
} | |
xhr.open('GET', 'https://your_awesome_url.com/tweet/', true); | |
xhr.setRequestHeader("Authorization", 'key=oNs3NZXPKF2_9NSAetkus'); | |
xhr.setRequestHeader("Content-type", "application/json"); | |
xhr.send(JSON.stringify(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment