Advertisement
Guest User

AJAX

a guest
Jan 30th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2. echo $form->dropDownList($model, 'service_id', CHtml::listData(Service::model()->findAll(array('order'=>'description,code')),'id','description'),
  3. array(
  4. 'prompt' => 'Select Service ...',
  5. 'ajax' => array(
  6. 'type'=>'POST', //request type
  7. 'url'=>CController::createUrl('updatePrice'), //url to call.
  8. 'data'=>array('service_id'=>'js:this.value'),
  9. 'dataType'=>'json',
  10. 'success'=>'js:function(data) {
  11. var price="#'.CHtml::activeId($model, 'price').'";
  12. $("#price_id").value(data.price);
  13. }',
  14. )
  15. )
  16. );
  17. ?>
  18.  
  19.  
  20. <?php // in the ServiceContoller.php of above
  21.  
  22. public function actionUpdatePrice() {
  23. if (Yii::app()->request->isAjaxRequest) {
  24. $service=Service::model()->findByPk($_POST['service_id']);
  25. if (isset($service))
  26. echo CJSON::encode(array(
  27. 'price'=>$service->defaultPrice,
  28. ));
  29. else
  30. echo CJSON::encode(array(
  31. 'price'=>0.00,
  32. ));
  33. }
  34. }
  35.  
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement