-
-
Save denysdovhan/3b3cb6cfb50b7a3e1b6a to your computer and use it in GitHub Desktop.
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
// Simple ajax function to avoid using jQuery (°-°) | |
var ajax = function (url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
xhr.send(); | |
xhr.onreadystatechange = function (e) { | |
if (e.target.status === 200 && e.target.readyState === 4) { | |
callback(e.target.response); | |
} | |
}; | |
}; | |
// Example | |
ajax("http://news.ycombinator.com/", function (data) { | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment