vendredi 8 juillet 2016

Ajax form submit in yii framework


I am sure the problem is with ajax. Without ajax it is fine. This is my javascript code:

 var frm = $('#register-form');
   $(document).on('submit', '#register-form', function (e) {


          $.ajax({

            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
                alert('Form was submitted!');
            }
        });

          e.preventDefault();
        });

  });

The form is:

 <form class="formclass" method="POST" action="<?php echo Yii::$app->request->baseUrl;?>/telephone/addnow/" role="form" enctype="multipart/form-data" id="register-form" novalidate="novalidate">
...
</form>

And the controller action is:

   public function actionAddnow()
        {
            if(Yii::$app->request->isAjax)
            {
                      //codes here
     }
}

The problem is that when I click the submit button, nothing is happening.


Aucun commentaire:

Enregistrer un commentaire