看来我无法访问jquery ajax成功函数内的$(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)怎么办 如果在该函数之外有对它的引用,则可以将其存储到变量中。
$(this)
$('#someLink').click(function() { var $t = $(this); $.ajax( ... , function() { $t.parent().remove(); }); }