如何访问ajax成功回调函数中的$(this) [英] how to access the $(this) inside ajax success callback function
本文介绍了如何访问ajax成功回调函数中的$(this)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎我无法在 jquery ajax 成功函数中访问 $(this).请看下面的代码.
It seems that i cannot access $(this) inside jquery ajax success function. please see below code.
$.ajax({
type: 'post',
url: '<?php echo site_url('user/accept_deny_friendship_request')?>',
data: 'action='+$action+'&user_id='+$user_id,
success: function(response){
//cannot access $(this) here $(this).parent().remove();
}
});
推荐答案
$(this)
应该是什么?如果您在该函数之外有对它的引用,则可以将其存储到变量中.
What should $(this)
be? If you have a reference to it outside that function, you can just store it into a variable.
$('#someLink').click(function() {
var $t = $(this);
$.ajax( ... , function() {
$t.parent().remove();
});
}
这篇关于如何访问ajax成功回调函数中的$(this)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文