2011-07-01 97 views
1

我有这样的事情......如何将变量传递给.post()?

$().ready(function() { 

    $(".post .comment_this").click(function() { 

     var comment_id = $(this).attr('rel'); 

     $.post(url_base + 'bio/community/get_comments', { 'comment_id' : comment_id }, function (response) { 

      console.log(comment_id); 

     }); 

    }); 

}); 

如何通过comment_id到该功能?所以我可以在那里使用它...

回答

4

你可以在那里使用它没有问题。

在Javascript中,您可以访问范围链中定义的每个变量,直至全局范围。本地定义的变量将覆盖来自链中的变量。

JavaScript Variable Scope on SO

+0

自动将现在的工作。^__^ – daGrevis

+0

@daGrevis我嘟some了一些魔法咒语:)。 – kapa

+1

单词杂音+1。 :) – vbence

0

应该罚款:

<button id="go">Go!</button> 
<div id="TestDiv">dd</div> 

$("#go").live('click', function(e) { 
    alert("win"); 
    var TestVar = "Message :)"; 
    $("#TestDiv").load("http://www.ryth.net/", function() { 
     alert(TestVar); 
    }); 
}); 

http://jsfiddle.net/EDx3A/1/