Simple AJAX Function
// 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);
});
Written by Danny Garcia
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Function
Authors
Chip Castle
21.68K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#