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 trialraj kanwar
4,043 PointsWhat 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?
2 Answers
Michael Mayer
6,161 PointsHi 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
9,910 Pointsin 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){
}
wuworkshop
3,429 Pointswuworkshop
3,429 PointsCould you paste the code that you're referring to?