gpt4 book ai didi

javascript - jquery如何在执行ajax调用后获取点击事件的索引

转载 作者:行者123 更新时间:2023-11-30 08:57:01 24 4
gpt4 key购买 nike

在下面的代码中,我将如何在我的 ajax 成功回调函数中使用 $(this).parents('#friendRequest').remove();,并使用 $(this ) 获取第一行点击事件的选择器?

jQuery(".notyAcceptFriendRequest").on('click', function() {
notyId = jQuery(this).attr("notyIdOne"); // pull in the id of the current selected notification
userProfilesUserId = $('#requestAlert').attr('userProfilesUserId'); // pull in the id of the current selected user profile id
if (notyId == userProfilesUserId) { // if notification id is the same as the user profiles id, do the following
$("#requestAlert").replaceWith('<span class="font1">You two are now friends</span>'); // the user profile friend requester will be replaced with the text
$(this).parents('#friendRequest').remove(); // find the '#friendRequest' id from the parent elements and fade it out
} else if (notyId != userProfilesUserId) {
/* the below will execute when the user
* clicks the 'Add' button and he/she is
* not on the targeted users page
*/
$.ajax({
type: "POST",
dataType: "JSON",
url: "<?=base_url()?>index.php/reguserDash/acceptFriendNoty",
data: {notyId: notyId},
json: {friendshipCaneled: true},
success: function(data) {
if(data.acceptNotyFriendSuccess == true) {
$(this).parents('#friendRequest').remove();
}
}
})
}
});

最佳答案

回调中的

this 与处理程序中的 this 不同。

您需要将 this 存储在局部变量中,然后在回调中使用该变量。

关于javascript - jquery如何在执行ajax调用后获取点击事件的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12701026/

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