Howdo I get the current element within $.ajax's success function?
Hi all,
I'm following the jquery official guide on developing plugins and I run into this situation where I need to retrieve the data associated with the current element and I don't know how do that. I will post a shortened and simplified version of my code below, hopefully some experts out there can shed some light on me
I need to access the current element $this inside my success function which is defined in var opts, however this seems to be impossible. I want to at least try to get which element is being clicked on
- var opts = {
ajax:{
url: 'http://www.bestofferbuy.com/contact_us.html',
data: {ajax_return_blocks:'rb_contact_us'},
success: function(data, textStatus, jqXHR){
// i need to access $this here
// if not possible, at least i want to know which element is being clicked on, but $(this) here seems to return the jquery ajax object
}
}
};
$("a").each(function(){
$this = $(this);
$this.bind("click", function(e){
if( (!$.browser.msie && e.button == 0) || ($.browser.msie && e.button == 0)) {
$.ajax(opts.ajax);
e.preventDefault();
}
});
})