开发者

jQuery passing variable strange syntax

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 erro开发者_运维技巧r] $.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.


Try

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜