Context lost when using $.post inside a delegated event handler. Bug?
I have some code that's a more involved version of this:
- $('#container_div').delegate('.trigger_button', 'click', function() {
- $.post('handler.php',
- { id: $(this).siblings('.item_id').val() },
- function(data) {
- $(this).siblings('.result_display').val(data.result);
- },
- 'json'
- );
- });
Normally, when I use .post in an event handler, "this" refers to the object that triggered the event. That doesn't happen in this case. When I use "this" the first time, to pull data parameters, it refers to the .trigger_button. But inside the .post callback, it refers to the AJAX call object instead. I don't think that's how it's supposed to work, is it? Is this a bug?