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 AJAX Basics (retiring) jQuery and AJAX jQuery’s AJAX Shorthand Methods

Weng Jeff Lee
Weng Jeff Lee
12,865 Points

$get() make me a little bit confuse

Hello, about an ajax shorthand methods. In this video, i get confuse of this

$.get("sidebar.html", function(response){
  $('#ajax').html(response);
})

The argument 'response', what it doing in the function? Is it the response for the 'sidebar.html'?

Thanks for anyone who try to explain.

Abhishek Bhardwaj
Abhishek Bhardwaj
3,316 Points

" $.get (or) jquery.get() " are both same here $ is jquery selecter and get is a function that contain three argument for example: $.get(url,data,callbak);

2 Answers

Leo Picado
Leo Picado
9,182 Points

It is, so whatever comes back from the AJAX GET request will be stored in response, you can print it to the console to check it out, something like:

$.get("sidebar.html", function(response){
  console.log(response);
});

More info over at http://api.jquery.com/jquery.get/

Marked as best answer

Kenneth Kim
Kenneth Kim
3,795 Points

Hi I would like to add something to the question.

With what Leo said, if I use the load method -> $('#ajax').load('sidebar.html'); how will i get the response variable? Is is safe to say that I should only use load() if I want to insert html content to the selected ID and use the $.get() to do more like create a custom function (callback) and other stuff ?