0

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.

1
  • I am not passing any data at the moment, I have left the {} as I will be soon. Commented Dec 2, 2009 at 7:04

2 Answers 2

6

Just change it to:

$.get("InfoRetrieve", { },addContent);

It will take care of passing data when it calls the function.

Sign up to request clarification or add additional context in comments.

1 Comment

When you tried to use it like this addContent(data), you were actually triggering the function, not passing a reference to it. By omitting the (data) you passed a reference to your function that $.get could call upon success.
0

Try wrapping it in a new function object:

$.get("InfoRetrieve", { },function() { addContent(data) });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.