English 中文(简体)
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) });




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签