Skip to content

Instantly share code, notes, and snippets.

@denysdovhan
Forked from dannygarcia/test.js
Created July 12, 2014 16:13
Show Gist options
  • Save denysdovhan/3b3cb6cfb50b7a3e1b6a to your computer and use it in GitHub Desktop.
Save denysdovhan/3b3cb6cfb50b7a3e1b6a to your computer and use it in GitHub Desktop.
// 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