Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,254 PointsDiscussion: AJAX with jQuery. Yay or Nay?
I've been enjoying working with AJAX over the past few days. That said, it was a little daunting.
I can probably commit this to the brain:
var url = "/scriptlocation.php"
var data = {
firstName: "Dave",
lastName: "McFarland"
};
var callback = function(response) {
};
$.get(url, data, callback);
But not this:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
if (xhr.status === 200) {
document.getElementById('ajax').innerHTML = xhr.responseText;
} else if (xhr.status == 404) {
} else if (xhr.status == 500) {
}
}
}
};
So I was blown away when I watched the first of the Stage 3 videos (AJAX Concepts) which talks about how jQuery makes an AJAX request so much simpler. Woohoo, simpler code for us all.
My question is, is it worth is learning to make AJAX Requests in pure JavaScript when jQuery takes care of the legroom for us?
Is it a detriment or a sign of weakness somehow if we do?
2 Answers
Roger Lüchinger
11,403 PointsI think what counts is the solution, and not how you got there. So if I have a choice, I will always go for the easier solution and not try it the hard way. jQuery is amazing and I don't see any reason not to use it – there are still enough other things to learn.
James Barnett
39,199 PointsThere's no agreement on this. If you google vanilla javascript
you will find a lot of people arguing for doing things without JavaScript. One really good reason is to understand how JavaScript works.