jQuery隐藏不起作用.post成功函数

cud*_*mer 2 html jquery post hide

任何人都可以告诉我为什么我的代码:$(this).parent().hide();工作(所选的div是隐藏的)当放在我的.post()喜欢之外:

$(document).on('submit', '.reply-message-form', function(e) {

        $(this).parent().hide();

        if($(this).children('.post-reply-message-textarea').val() == '')
            return false;

        $.post("<?php echo Yii::app()->createUrl('event/view', array('id'=>Yii::app()->controller->actionParams['id'])); ?>", 
        $(this).serialize(), function(response) {

            var responseObject = jQuery.parseJSON(response);
            // if successful.. process..
            if (responseObject.success == true) {

            } else {
                alert('failed');
            }

        });
        return false;
    }) ;
Run Code Online (Sandbox Code Playgroud)

但是,如果.hide()放在里面.post()成功,函数没有任何反应..?!内部代码:

$(document).on('submit', '.reply-message-form', function(e) {

        if($(this).children('.post-reply-message-textarea').val() == '')
            return false;

        $.post("<?php echo Yii::app()->createUrl('event/view', array('id'=>Yii::app()->controller->actionParams['id'])); ?>", 
        $(this).serialize(), function(response) {

            $(this).parent().hide();
            return false;
            var responseObject = jQuery.parseJSON(response);
            // if successful.. process..
            if (responseObject.success == true) {

            } else {
                alert('failed');
            }

        });
        return false;
    }) ;
Run Code Online (Sandbox Code Playgroud)

只是为了清除任何疑问 - responseObject.success确实== true(我已通过警报确认等).

提前致谢!

fli*_*iim 5

尝试,因为当你在回调中移动时,$(this)不一样.

$(document).on('submit', '.reply-message-form', function(e) {
    var elt = $(this).parent();
    if($(this).children('.post-reply-message-textarea').val() == '')
        return false;

    $.post("<?php echo Yii::app()->createUrl('event/view', array('id'=>Yii::app()->controller->actionParams['id'])); ?>", 
    $(this).serialize(), function(response) {

        $(elt).hide();
        return false;
        var responseObject = jQuery.parseJSON(response);
        // if successful.. process..
        if (responseObject.success == true) {

        } else {
            alert('failed');
        }

    });
    return false;
}) ;
Run Code Online (Sandbox Code Playgroud)