我刚刚开始学习AJAX 在发帖之前,我已经搜索并引用了以前提出的问题,例如 this但这没有帮助 我的代码是:
$('.del').click(function(){
$(this).parent().hide('slow');
$.get( "index.php", {del:$(this).attr('id')}).done(function(data){
if (data==='1') {
$(this).parent().remove();
}
else{
$(this).parent().show('slow');
}
});
});
if
中的 jquery 语句以及 else
未执行为了验证一切是否顺利,我在语句并且它成功弹出,但 jquery 语句不起作用。问题是什么以及如何解决这个问题?
最佳答案
我相信您的 $(this)
引用在该范围内不正确。尝试:
$('.del').click(function(){
var $this = $(this);
$this.parent().hide('slow');
$.get( "index.php", {del:$this.attr('id')}).done(function(data){
if (data==='1') {
$this.parent().remove();
}
else{
$this.parent().show('slow');
}
});
});
关于javascript - 如果 AJAX 成功/失败后,jquery 无法在内部工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24273555/