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 Posting Data with jQuery

raj kanwar
raj kanwar
4,043 Points

What is the purpose of response included in the function which runs inside jquery post method at the end?

What is the purpose of response included in the function which runs inside jquery post method at the end?

Could you paste the code that you're referring to?

2 Answers

Hi Raj,

Ajax functions usually have a 'callback' function which will tell you if there is a success or failure, and then allows you to execute a script in case of failure.

Jeremiah Lugtu
Jeremiah Lugtu
9,910 Points

in function parameters, names are not strictly defined. You can name it whatever you want, so long as you understand the purpose of it.

In this case, it's an AJAX callback, the parameter of 'response' within the callback's anonymous function 'function(response)' is the jQuery equivalent of responseText, when creating AJAX requests using vanilla JS... responseText or response is what will happen when the AJAX Request is processed/completed:

$('#signup').html("<p>Thanks for signing up!</p>")

Remember that jQuery is simply a library, every jQuery API has a corresponding JS structure

In the case of jQuery AJAX callback functions... Usually you will see 'response' or 'data' within the callback function parameter

eg

$.get(url, data, function(data){

}

but generally, you can name it anything you want

eg

$.post(url, data, function(awesome){

}