Advertisement
pebriana

Ajax Button Post YII

Sep 9th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. up vote 2 down vote
  2. http://stackoverflow.com/questions/13837333/ajax-button-post-in-yii
  3.  
  4. To pass the data, you need to add it to your ajax array, e.g.:
  5.  
  6. <?php
  7. echo CHtml::ajaxSubmitButton('ButtonName',Yii::app()->createUrl('advert/LoadAdvertFromSay'),
  8. array(
  9. 'type'=>'POST',
  10. 'data'=> 'js:$("#dataContainer").serialize()',
  11. 'success'=>'js:function(string){ alert(string); }'
  12. ),array('class'=>'someCssClass',));
  13. ?>
  14.  
  15. In this case, all input type elements in the element with id dataContainer would be submitted, and could be accessed via $_POST.
  16.  
  17. Obviously, the JS could be more complicated, you could get values from certain elements, and build your own object, e.g.:
  18.  
  19. 'data' => 'js:{"field1": $("#input1").val(), "pageTitle": $("title").text() }'
  20.  
  21. Then, in your controller, you could access $_POST["field1"] and $_POST["pageTitle"], though I generally tend to access items via CHttpRequest::getParam() as then I can get either POST or GET values, e.g. CHttpRequest::getParam('field1')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement