2011-07-01 16 views
1

私はその関数へcomment_idを渡すために、どのようにこのような何か...変数を.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); 

     }); 

    }); 

}); 

がありますか?だから私はそこにそれを使用することができます...

答えて

4

問題なく使用できます。

Javascriptでは、スコープチェーンで定義されたすべての変数にグローバルスコープまでアクセスできます。局所的に定義された変数は、チェーンから来た変数よりも優先されます。

JavaScript Variable Scope on SO

+0

自動的にそれが機能するようになりました。^__^ – daGrevis

+0

@daGrevis私はいくつかの魔法の呪文をmurmurred :)。 – 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/

関連する問題