Reputation: 83
I was reading something about Ajax and jQuery and I saw this code:
$.ajax({
url: "test.html",
cache: false
}).done(function( html ) {
$("#results").append(html);
});
I don't see anywhere the declaration of "html", how will the code know what to append?
P.S. It might be a stupid question, but i didn't find the answer to this question anywhere :/
Upvotes: 0
Views: 54
Reputation: 2290
When the ajax call completes it will pass data into the function defined for done.
.done(function(html){
html is not "defined" here, but rather the name of the variable that receives the data. Once the placeholder is defined you can use it anywhere in your function.
For example, if you have
function myFunc(foo){
alert(foo);
}
and then did
myFunc(1234);
//result 1234
myFunc("test");
//result "test"
So, really html is just what this person chose to call the data that is received from the ajax call. If you read the tutorial's on jQuery's site, most of the time they name this variable "data"
Upvotes: 1