More information about this topic
Reset database  | 
Ajax request using ajaxLink

demos/yii_playground/protected/modules/AjaxModule/views/ajax/ajax_request.php


echo CHtml::ajaxLink(
	'Test request',          // the link body (it will NOT be HTML-encoded.)
	array('ajax/reqTest01'), // the URL for the AJAX request. If empty, it is assumed to be the current URL.
	array(
		'update'=>'#req_res'
	)
);
?>

<div id="req_res">...</div>

protected/modules/AjaxModule/controllers/AjaxController.php

	public function actionReqTest01() {
		echo date('H:i:s');
		Yii::app()->end();
	}
Ajax request using ajaxButton
...

demos/yii_playground/protected/modules/AjaxModule/views/ajax/ajax_request.php


<div class="form">
<?php echo CHtml::beginForm(); ?>

<div class="row">
<?php echo CHtml::label('Some text', 'some_text'); ?>
<?php echo CHtml::textField('some_text', date('H:i:s')); ?>
</div>

<?php
echo CHtml::ajaxSubmitButton(
	'Submit request',
	array('ajax/reqTest03'),
	array(
		'update'=>'#req_res02',
	),
	array(
		'type'=>'submit',
	)
);
?>

<?php echo CHtml::endForm(); ?>
</div><!-- form -->

<div id="req_res02">...</div>

protected/modules/AjaxModule/controllers/AjaxController.php

	public function actionReqTest03() {
		echo CHtml::encode(print_r($_POST, true));
	}