I am trying to use CHtml::ajax() function to send a request from the view to the controller.
The view display 4 input fields which it sends to the controller upon submit.
The controller makes an internal calculation and creates a request id ($reqid) which it send back to the view using render(). This part works as it should.
The view (Diag.php)
<?php /* @var $this DiagFormController */ /* @var $model DiagForm */ /* @var $form CActiveForm */ ?> <div class="form"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'diag-form-Diag-form', 'enableAjaxValidation'=>true, )); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->label($model,'site_id'); ?> <?php echo $form->textField($model,'site_id') ?> </div> <div class="row"> <?php echo $form->label($model,'link_id'); ?> <?php echo $form->textField($model,'link_id') ?> </div> <div class="row"> <?php echo $form->label($model,'device_name'); ?> <?php echo $form->textField($model,'device_name') ?> </div> <div class="row"> <?php echo $form->label($model,'device_level'); ?> <?php echo $form->textField($model,'device_level') ?> </div> <div class="row submit"> <?php echo CHtml::button('Get Diagnostics', array('submit' => array('Diag/getDiagnostics'))); ?> </div> <div class="row"> <?php echo $form->label($model,'result:'); ?> <?php echo $form->textArea($model,'result', array('maxlength' => 300, 'rows' => 10, 'cols' => 80)); ?> <?php if ($ajax_flag == 'true') { CHtml::ajax(array( 'url'=>yii::app()->createUrl('Diag/CheckStatus'), 'type'=>'POST', 'data'=>array('request'=>$reqid), 'success'=>"function(){ alert('ok');}" )); } ?> </div> <?php $this->endWidget(); ?> </div><!-- form -->
The view is trying to make ajax call to a different controller action (actionCheckStatus) however the function is never called.
The controller (DiagController.php)
class DiagController extends Controller { public function actionIndex() { } public function actionGetDiagnostics() { // Internal logic which works fine } public function actionCheckStatus() { // Function never gets called !!! }
Notes:
I am using yii 1.1.13.
I am working on a localhost (Apache).
I tried replacing CHTML::ajax() with CHTML::ajaxLink() and it worked...
Again it seems that the ajax call doesn't reach the controller (debugging verifies this).
What am I doing wrong?
Thanks for your help