Yii::app()->clientScript->registerCoreScript('yii'); $this->widget('yii\widgets\Pjax', array( 'id' => 'my-pjax-container', 'options' => array('timeout' => 10000), )); echo CHtml::ajaxLink( 'Click me', array('/site/index'), array( 'update' => '#my-pjax-container', 'success' => 'function() { alert("AJAX call completed!"); }', 'beforeSend' => 'function() { alert("AJAX call initiated!"); }' ) );
Yii::app()->clientScript->registerCoreScript('yii'); $this->widget('yii\widgets\Pjax', array( 'id' => 'my-pjax-container', 'options' => array('timeout' => 10000), )); $this->beginWidget('CActiveForm', array( 'id' => 'my-form', 'enableAjaxValidation' => true, 'clientOptions' => array('validateOnSubmit' => true), 'htmlOptions' => array( 'data-pjax' => true, 'class' => 'well form-horizontal' ), )); // form fields... echo CHtml::submitButton('Save'); $this->endWidget();In this example, we use the Pjax widget in combination with the `CActiveForm` widget to create a form that will submit via AJAX and validate on submit. We set the `data-pjax` attribute to true on the form element to specify that the form should be submitted via Pjax, and add some additional HTML options to style the form. Finally, we add a submit button to the form and close the widget.