Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery hide内部不工作。post success函数_Jquery_Html_Post_Hide - Fatal编程技术网

jQuery hide内部不工作。post success函数

jQuery hide内部不工作。post success函数,jquery,html,post,hide,Jquery,Html,Post,Hide,谁能告诉我为什么我的代码:$(this.parent().hide()放置在my.post()之外时起作用(选定的div被隐藏),如: $(document).on('submit', '.reply-message-form', function(e) { $(this).parent().hide(); if($(this).children('.post-reply-message-textarea').val() == '')

谁能告诉我为什么我的代码:
$(this.parent().hide()放置在my
.post()之外时起作用(选定的div被隐藏),如:

$(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;
    }) ;
为了澄清任何疑问,responseObject.success确实==true(我已经用警报等确认了这一点)

提前谢谢

试试看,因为在post回调中移动时,$(这个)不一样

$(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;
}) ;
$(文档).on('submit','reply message form',函数(e){
var elt=$(this.parent();
if($(this).children('.post reply message textarea').val()='')
返回false;
$邮政编码(“,
$(this).serialize(),函数(响应){
$(elt.hide();
返回false;
var responseObject=jQuery.parseJSON(响应);
//如果成功..过程。。
if(responseObject.success==true){
}否则{
警报(“失败”);
}
});
返回false;
}) ;

不再表示提交的表单,因为它位于ajax调用的回调中。在进行ajax调用之前,请使用以下命令设置一个变量

var myForm = this;

然后在您的成功回调中,引用
$(myForm)

您打败了我。我喜欢这种方式,因为您只需要成功回调中的父级。
var myForm = this;