views:

38

answers:

2

I have the following two functions:

$(".content").click( function() {
    var id = this.id;
    $.get("InfoRetrieve", { theid:id }, addContent );
});

function addContent(data){
    $("#0001").append(data);
}

I need to pass the 'id' variable from the first function to the addContent function, I don't quite get how this works. In the above example I am passing the "data" variable to the addContent function implicitly (it seems). Will I do something like this:

In the first function addContent -- becomes --> addContent(id)

In the second function

addContent(data) -- becomes --> addContent(data,id)

or something completely different?

Edit: I made modifications as per Denis' suggestion, however now it seems as if nothing happens - previously I had sone some hard coding so I was able to see my "data" being appended to the proper place:

$(".content").click( function() {
var id = this.id;
$.get("InfoRetrieve", { theid:id }, addContent {addContent(data, id)}  );
});

function addContent(data, id){
alert(id);
$("#0001").append(data);
}

Another edit Firefox says:
missing ) after argument list [Break on this error] $.get("InfoRetrieve", { theid:id ..., addContent {addContent(data, id)} );\n
.... but this doesn't seem to make sense since as far as I can see all the brackets match up with something else.

+1  A: 

Try

$.get("InfoRetrieve", { theid:id }, function(data) {addContent(data, id)} );
Deniss Kozlovs
Hi Deniss, thanks for your help. But that didn't seem to work. I have updated the question.
Ankur
the code in your update looks nothing like deniss' suggestion, which should definitely work.
David Hedlund
You're right - a wtf moment right there.
Ankur
+1  A: 

Try:

$(".content").click( function() {
  var id = this.id;
  $.get("InfoRetrieve", { theid:id }, function() {
    addContent(data, id);
  });
});

function addContent(data, id){
  alert(id);
  $("#0001").append(data);
}
cletus