Take the 2-minute tour ×

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){

It doesn't seem to work, can you see why.

share|improve this question
I am not passing any data at the moment, I have left the {} as I will be soon. –  Ankur Dec 2 '09 at 7:04
add comment

2 Answers

up vote 6 down vote accepted

Just change it to:

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

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

share|improve this answer
It makes no sense that it works that way but it works! –  Ankur Dec 2 '09 at 7:09
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. –  Doug Neiner Dec 2 '09 at 7:12
I see :) thanks –  Ankur Dec 2 '09 at 7:15
@dcneiner: +1, you got it, I mis-readed the question... –  CMS Dec 2 '09 at 7:19
add comment

Try wrapping it in a new function object:

$.get("InfoRetrieve", { },function() { addContent(data) });
share|improve this answer
add comment

Your Answer


