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 trial

JavaScript Asynchronous Programming with JavaScript Understanding Promises Create a Promise

Seems better with jQuery ajax call

I don't understand why we spend an entire unit learning jQuery then we go back to vanilla JS. It's kind of frustrating going back and forth on that. I redid the getJSON function with a jQuery AJAX call instead.

function getJSON(url, callback) {
  $.ajax({
    type: "GET",
    url: url,
    dataType: "JSON",
    success: function (response) {
      return callback(response);
    }
  });
}

This to me seems much more succinct and it works perfectly. Why would we not always use jQuery for AJAX calls?

2 Answers

Gabriel Plackey
Gabriel Plackey
11,064 Points

I think it's good to know how to do it in vanilla JaveScript, as doing it through jQuery AJAX might not always be an option.

I agree with you though, the jQuery way is much better and easier. I think that's jQuery in general though.

jQuery is essentially syntactic sugar. It's good to know what jQuery is actually doing behind the scenes and not having to load an entire library to run a simple XHR request is a bonus as well.