Skip to content

Instantly share code, notes, and snippets.

@toadkicker
Last active December 18, 2015 17:59
Show Gist options
  • Save toadkicker/5822980 to your computer and use it in GitHub Desktop.
Save toadkicker/5822980 to your computer and use it in GitHub Desktop.
jQuery vs native
//ajax
$.ajax({
url: '/endpoint'
}).done(function(data){
// do something awesome
}).fail(function(xhr){
// sad little dance
});
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
var completed = 4;
if(xhr.readyState === completed){
if(xhr.status === 200){
// do something with xhr.responseText
}else{
// handle the error
}
}
};
xhr.open('GET', '/endpoint', true);
xhr.send(null);
//end ajax
//events
$('button').on('click', function(){
//do stuff
});
var element = document.getElementsByTagName("button");
if (element.addEventListener){ //removeEventListener
element.addEventListener(type, handler, false);
}else if (element.attachEvent){ //detacheEvent
element.attachEvent('on' + type, handler);
}else{
//what kind of browser are you then?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment