Created
May 21, 2014 13:51
-
-
Save icodesido/e293cf72b582fddcbc3d to your computer and use it in GitHub Desktop.
Raw vs jQuery AJAX
This file contains hidden or 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
$.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