Yii:CJuiDalog和CJSON的回应

时间:2012-01-15 16:13:10

标签: php ajax yii

我想在模态窗口中创建注册表单。一切正常,但是。 未处理JSON响应,firebug> [08:26:54.678]未捕获的异常:语法错误,无法识别的表达式:{“status”:“success”} 没有模态窗口一切正常。响应正在进行和处理。 欢迎任何帮助和建议。

控制器:

public function actionSignup()

    {
    if(Yii::app()->request->isAjaxRequest) {
       $user = new Signup(Signup::SCENARIO_SIGNUP);


   if(Yii::app()->user->isGuest)
   {
       if(isset($_POST['ajax']) && $_POST['ajax']==='register-form')
{
    echo CActiveForm::validate($user);
    Yii::app()->end();
}
        if(isset($_POST['Signup']))
            $user->attributes = $_POST['Signup'];

                if($user->save())                       
                {
                    Yii::app()->user->login(new UserIdentity($user));

                echo CJSON::encode(array(
                    'status'=>'success', 

                    )); 

                $this->activationKey($user);

                exit;      


        }
     $this->renderPartial('_finalFormAjax', array('model'=>$user),false,true);

   }

查看

  <?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'mydialog',
    'options'=>array(
        'title'=>'Регистрация',
        'autoOpen'=>true,
         'modal'=>true,
        'width'=>550,
        'height'=>470,
        'draggable'=>false,
        'resizable'=>false,
    ), ?>
   ));


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

)); ?>



    <?php  echo CHtml::ajaxSubmitButton('Зарегистрироваться','', 
                array(
                    'type' => 'POST',
                    'dataType'=>'json',
                    'beforeSend' => 'function() {
                            $("#register-form").addClass("loading");
                    }',
                    'complete' => 'function(){
                            $("#register-form").removeClass("loading");
                    }',
                    'success'=>"function(data)     
                    {
                        if(data.status == 'success')
                    {    
                            $('#mydialog').load('/whowithme/signup/finalstep'); 
                    }}",

                    )
            ); ?>

    <?php $this->endWidget(); ?>



    <?php $this->endWidget('zii.widgets.jui.CJuiDialog '); ?>

1 个答案:

答案 0 :(得分:0)

而不是 -

   'success'=>"function(data)     
   {
      if(data.status == 'success')
      {
         $('#mydialog').load('/whowithme/signup/finalstep'); 
      }
   }"

尝试 -

'success'=> "function(response)     
   {
      var data = $.parseJSON(response);

      if(data.status == 'success')
      {
         $('#mydialog').load('/whowithme/signup/finalstep'); 
      }
   }"