I have been trying to use this inside an ajax function to refer the event target . but it seems that is not the way I think.
for example:
$('#test').live('click',function(){
$.ajax({
type:'post',
url:
data:...,
success:function(mes){
$(this).append('mes');
}
});
});
so here $(this) does not refer to the (‘#test’) selector. what does it refer to??
thanks for any explanation.
Inside the success callback
thisrefers to a global object created by jQuery containing information about the AJAX rerquest. If you want to get the original DOM element you could capture it in a closure:or if you don’t like closures you could pass it as a key/value pair of the request:
This could be useful in scenarios where the
successcallback is not an anonymous function.