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

Matt Schaefer
Matt Schaefer
6,039 Points

$.get() number of parameters

$.get() has a total of four parameters, according to the documentation. We were shown three in the video:

$.get(url, data, callback);

However, in a later example in the video, we call $.get() with only two arguments because we don't have any data:

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

What are the rules when omitting a arguments in this way? Since the callback is in the second argument, does jquery just "know" that we don't have data?

1 Answer

Alexandre Babeanu
Alexandre Babeanu
10,947 Points

Only the url parameter really needs to be set.

Data argument is additional data. If there is no data specified, yes jquery will know there is no additional data to be sent.

in the same way If the callback argument is omitted, the return result will simply be ignored since no action is set.

and finally dataType has a default value. So if you don't specify the dataType argument it will take it's default value.