如何访问$(本)内的ajax成功回调函数 [英] how to access the $(this) inside ajax success callback function
本文介绍了如何访问$(本)内的ajax成功回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看来我不能访问$(本)内的jQuery阿贾克斯成功的功能。请参见下面的code。
$。阿贾克斯({
类型:'后',
网址:'?< PHP的回声SITE_URL(用户/ accept_deny_friendship_request')?>',
数据:'行动='+ $动作+'和; USER_ID ='+ $ USER_ID,
成功:函数(响应){
//不能访问$(本)这里$(本).parent()删除()。
}
});
解决方案
我应该 $(本)
是?如果你有一个参考吧的功能之外,你可以将其存储到一个变量。
$('#someLink)。点击(函数(){
变量$ T = $(本);
$就(...,函数(){
$ t.parent()删除()。
});
}
It seems that i cannot access $(this) inside jquery ajax success function. please see below code.
$.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();
}
});
解决方案
What should $(this)
be? If you have a reference to it outside that function, you can just store it into a variable.
$('#someLink').click(function() {
var $t = $(this);
$.ajax( ... , function() {
$t.parent().remove();
});
}
这篇关于如何访问$(本)内的ajax成功回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文