在下面的代码中,我将如何$(this).parents('#friendRequest').remove();
在我的 ajax 成功回调函数中使用,并用于$(this)
在第一行获取 click 事件的选择器?
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();
}
}
})
}
});