Can any provide me a sample example for how to use ajax in yii? . It will be very much helpful for me as I am new to Yii.
Thanks
Can any provide me a sample example for how to use ajax in yii? . It will be very much helpful for me as I am new to Yii.
Thanks
Hi FIJU,
it is depends on you that how you want to use a ajax features on your project.Yii have lots of scope to use ajax like ajaxbutton,ajax link and all…
But if you are looking for a ajax form validation then dont need to be worried.It is a inbuilt feature of Yii.
Have a look on it.
Enable ajax validation in your CactiveForm widget
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user-registration-form',
'enableAjaxValidation'=>true, 'stateful'=>true, 'htmlOptions'=>array('enctype' => 'multipart/form-data'),
)); ?>
Add this code in your Action
if(isset($_POST['ajax']) && $_POST['ajax']==='user-registration-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
There is only one thing to remember…
$_POST['ajax']==='user-registration-form'
Where "user-registration-form" will be your form Id.
That’s it…!!
Hi… i am using this ajax method for ma form submission… what i don understand is… where do i set $_POST[‘ajax’]??
There is only one thing to remember..
$_POST['ajax']==='user-registration-form'
Where "user-registration-form" will be your form Id.
That's it..!!
in my case it say $_POST[‘ajax’] is not set…
Thanks nice one. One shot look and implement now the birds singing