开发者

jQuery, how to call a function while passing a variable

开发者 https://www.devze.com 2022-12-13 04:38 出处:网络
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))开发者_运维问答;

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) });
0

精彩评论

暂无评论...
验证码 换一张
取 消