ajaxsubmit无法提交返回null

时间:2014-08-11 12:29:46

标签: yii

我收到错误200.表单永远不会发布,所有字段都返回空白。我还检查了列是否是必需的,我将所有内容都设置为null。我有另一种形式,看起来像这样,它工作正常。有任何想法吗?

   <?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'thisForm',
    )); ?>
//form
    <?php 
            echo CHtml::ajaxSubmitButton('Add',
                    Yii::app()->createUrl("url/controller"),
                    array(
                            'type'=>'POST',
                            'dataType'=>'text json',
                            'data'=>'js:$("#thisForm").serialize()',
                            'success'=>'js:function(data) {
                                if(data.status=="success")
                                     $.fn.yiiGridView.update("osb123");
                             }',
                            'error'=>'function (xhr, ajaxOptions, thrownError) {
                                alert(xhr.status);
                                alert(thrownError);
                            }'
                    ));
            ?>

    public function actionController()
        {
            $model=new Model;

            if($_POST['Model'])
            {
                $model->attributes=$_POST['Model'];
                $model->temporary_id = Yii::app()->user->user_id;
                $model->cost = floatval($_POST['Model']['cost']);
                $model->active = "Y";

                if($model->validate()){
                    echo CJSON::encode(array('status'=> 'success',
                            'data'=>var_dump($_POST['Model'])
                            ));
                }
                else{
                    $error = CActiveForm::validate($model);
                    echo CJSON::encode(array('status'=> 'error', 'error'=>var_dump($_POST['Model'])));
                }
            }else echo CJSON::encode(array('status'=>'error','error'=>'Not Set'));

        }

1 个答案:

答案 0 :(得分:0)

  1. url的ajax按钮中,您设置了Yii::app()->createUrl("url/controller"),而通常正确的语法为Yii::app()->createUrl("controller/action")您是否可以使用调试工具(Ctrl + Shift + I或F12)进行检查POST请求并查看yii生成的实际URL?

  2. 您有beginWidget,还有endWidget吗?