【问题标题】:ajax not clearing form on submitajax 在提交时未清除表单
【发布时间】:2014-01-11 01:02:22
【问题描述】:

我有一个表单,想通过 ajax 提交。它发布但不清除表单 onclick 成功。我也试过 .done(function)。我也尝试过有关成功和错误的警报数据(认为一定是错误的),但它也没有发出任何警报。

<?php echo CHtml::ajaxSubmitButton(
    'Comment',
    'review/ajaxComment',
        array(
            'type'=>'POST',
            'dataType'=>'json',
            'success'=>'js:function(data){
           if(data.result==="success"){
              document.getElementById("review-form").reset();
              alert("this worked");
           }else{
              console.log(error)
           }
       }'
    )
)?> 

表格

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'review-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true),)); ?>

<?php echo $form->errorSummary($model); ?>
<div class="rating-row">
    <?php $this->Widget('CStarRating', array(
            'model'=>$model,
            'attribute'=> 'star',
            'minRating'=>.5 ,
            'maxRating'=>5 ,
            'starCount'=>5 ,
            'ratingStepSize'=>.5 
    ));?>
</div>

<div class="rating-row">
<label>Reviews</label>
    <?php echo $form->textArea($model,'review'); ?>
    <?php echo $form->error($model,'review'); ?>
</div>

【问题讨论】:

  • 能否请您张贴您的表单html?
  • 这是一个非常直接的形式。
  • 你从服务器得到什么响应?

标签: ajax yii


【解决方案1】:

方法一:

为所有textboxtextareaDropdown 分配一个类。例如frm_inp_ctrl

然后,在 ajax 中执行 $(".frm_inp_ctrl").val(""); done()

方法二:

使用下面的表单 ID 进行重置。

 $("#review-form :input").val("");

【讨论】:

    猜你喜欢
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多