gpt4 book ai didi

jquery - 如何访问ajax成功回调函数中的$(this)

转载 作者:行者123 更新时间:2023-12-03 21:29:57 25 4
gpt4 key购买 nike

似乎我无法在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com