Skip to content

Instantly share code, notes, and snippets.

@icodesido
Created May 21, 2014 13:51
Show Gist options
  • Save icodesido/e293cf72b582fddcbc3d to your computer and use it in GitHub Desktop.
Save icodesido/e293cf72b582fddcbc3d to your computer and use it in GitHub Desktop.
Raw vs jQuery AJAX
$.getJSON('/my/url', function(data) {
});
vs
request = new XMLHttpRequest();
request.open('GET', '/my/url', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400){
// Success!
data = JSON.parse(request.responseText);
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment