What context is the jQuery.post callback function invoked in?
<p>Lets say for example:</p>

<pre><code>$(".button").click(function() {

    $.post("commandrunner.php",
        {
            param1: 'value',
            param2: 'value2',
            param3: 'value3'
        },
        function(data, textStatus) {
            $(this).parent().after('&lt;p&gt;button clicked&lt;/p&gt;');
        },
        "json"
    );

});
</code></pre>

<p>I ran this and it didn't work. I tried a couple of things before I theorized the callback wasn't being invoked in the context of this particular ".button" and so $(this) was useless. This worked instead:</p>

<pre><code>$(".button").click(function() {
    var thisButton = $(this);

    $.post("commandrunner.php",
        {
            param1: 'value',
            param2: 'value2',
            param3: 'value3'
        },
        function(data, textStatus) {
            thisButton.parent().after('&lt;p&gt;button clicked&lt;/p&gt;')
        },
        "json"
    );

});
</code></pre>

<p>This feels like a bit of a hack. Is this the right way to get a reference to the clicked on button? And what context is that (or any other callback) invoked in?</p>

<p>Thanks!</p>

<p>Ali</p>
