jQuery, how to call a function while passing a variable
I want to use jQuery's .get method to send an ajax call to the server.
I am using this line:
$.get("InfoRetrieve", { },addContent(data))开发者_运维问答;
As you can see I want to call a function call addContent and pass it the data that is retrieved from the server.
The function addContent is below:
function addContent(data){
$("#0001").append(data);
}
It doesn't seem to work, can you see why.
Just change it to:
$.get("InfoRetrieve", { },addContent);
It will take care of passing data
when it calls the function.
Try wrapping it in a new function object:
$.get("InfoRetrieve", { },function() { addContent(data) });
精彩评论