Yii Ajax Tutorials

Yii Ajax Request and JSON Response Array

This tutorial will help you to understand the details of yii ajax request and response from controller. I will change the product list based on category change via ajax. When i change the “category” dropdown, Ajax will send the request to “site/productlist” controller. Now controller will get and process the data then finally It will return the json encoded array.Using this response we can update product drop down list.In view.php<?php […]... Read More »

Insert data into Dropdownlist by ajax request in yii

This turorial have the details of dynamic data insertion to dropdownlist using ajax. I added the source code below for this concept. We have two dropdownlist in form “usercategory”,”usertype”. When we change the usercategory, usercategory related usertype will show in “usertype” dropdownlist.In view.php <div class="row"> <?php echo $form->labelEx($model,'usercategory'); ?> <?php $categories=Yii::app()->Datacomponent->usercategory(); echo $form->dropdownlist($model, 'usercategory', $categories, array( 'empty'=>'Select Category ', 'ajax'=>array( 'type'=>'POST', 'url'=>CController::createUrl('default/usertype'), 'update'=>'#User_usertype', 'data'=>array('categoryid'=>'js:this.value'), ), ) ); ?> <?php echo […]... Read More »

Ajax Submit Button in Yii

Normally we will use the form submit action via post or get method with page submit option. With out page refresh we can submit the form using ajax concept. It will be faster than page reload. This post will help you to under stand AjaxSubmitButton instead of submitButton in yii.ajaxSubmitButton With Form <div class="form"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'user-form', 'enableAjaxValidation'=>false, )); ?> <div class="row"> <?php echo $form->labelEx($model,'companyname'); ?> <?php echo $form->textField($model,'companyname', […]... Read More »

CHtml Ajax Button in Yii

Example 1:In view.php page Write Follwing source code <?php echo CHtml::ajaxButton( 'Submit request', array('test/function'), array('data'=>array('test'=>$model->id)), array('update'=>'#update_selector') //this is the update selector of yours $('#update_selector').load(url); ); ?> In controller.php write following source code public function actionFunction() { if(Yii::app()->request->isAjaxRequest) { $this->renderPartial("_form",array('model'=>$model),false,true); Yii::app()->end(); } } Example 2: <?php echo CHtml::ajaxButton( 'Save', array('user/useraction'), array('data'=>array( 'id'=>$model->year_id, 'usertype'=>'js:$("#usertype").val()', 'username'=>'js:$("#username").val()', ) 'type'=>'POST', ); ?>... Read More »

Checkbox value in Ajax Request of Yii

This is one of the way to send data dynamicallay in ajaxbutton request of yii.When you click on ajaxbutton We will get the selected checkbox value and send this via ajax <?php Yii::app()->clientScript->registerScript('checkBoxSelect', " function callData() { fileid= $(\"input[name='usergroup[]']:checked\").map(function() { return this.value; }).get(); return 'id='+fileid; } "); ?> <?php echo CHtml::ajaxButton( 'User',CController::createUrl('user/active'), array( 'type' =>'POST', 'data'=>"js:callData()", //or append data here 'url'=> 'user/active', ), array('id'=>'activebtn') ); ?>... Read More »

Yii 1.0 Ajax search using Radio Buttons

Would you like to trigger one ajax request While clicking on Radio button, This post will help you to get radio button ajax request.In _search.php (form) <div class="wide form"> <?php $form=$this->beginWidget('CActiveForm', array( 'action'=>Yii::app()->createUrl($this->route), 'method'=>'get', )); ?> <div class="row"> <?php echo $form->radioButtonList( $model, 'status', array( '1'=>'Active', '2'=>'Inacitve' ), array( 'template'=>'{input}{label}', 'separator'=>'', 'labelOptions'=>array('style'=>'padding-left:13px'), 'style'=>'float:left;', 'onclick'=>CHtml::ajax(array( 'success'=>"$('.search-form form').submit()", )) ) ); ?> </div> <?php $this->endWidget(); ?> </div> In Model.php public function searchfiles() { […]... Read More »

Yii Ajax

Ajax Submit ButtonAjax ButtonAjax LinkAjax Support Ajax Submit ButtonAjax submit button can submit the current form in POST method. public static string ajaxSubmitButton( string $label, mixed $url, array $ajaxOptions=array ( ), array $htmlOptions=array ( ) ) $lable – the button label$url – the URL for the AJAX request. If empty, it is assumed to be the current URL.$ajaxOptions – data, success, update, replace,etc..;$htmlOptions – add HTML attributes here ex. name, id […]... Read More »