javascript - 如果 AJAX 成功/失败后,jquery 无法在内部工作

标签 javascript jquery ajax

我刚刚开始学习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/

相关文章:

javascript - Mozilla Firefox 问题。 HTML 选择(下拉菜单)某些选项的颜色

javascript - html canvas动画卡顿

javascript - 解析云代码替代方案

javascript - jQuery 和 Twitter Bootstrap - 下拉列表拆分

javascript - Bootstrap-multiselect 非常慢,有大量选项

javascript - 使表单在刷新时不提交

javascript - 动态命名的局部变量,用于加载模块

javascript - 如何导出可观察值并分配给变量?

jquery - 打开日期选择器上的“今天”按钮

javascript - 递归函数在第一个循环后停止