似乎我无法在 jquery ajax success 函数中访问 $(this) 。请参阅下面的代码。
$.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)
应该是什么?如果您在该函数之外有对它的引用,则可以将其存储到变量中。
$('#someLink').click(function() {
var $t = $(this);
$.ajax( ... , function() {
$t.parent().remove();
});
}
关于jquery - 如何访问ajax成功回调函数中的$(this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2643798/