Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- up vote 2 down vote
- http://stackoverflow.com/questions/13837333/ajax-button-post-in-yii
- To pass the data, you need to add it to your ajax array, e.g.:
- <?php
- echo CHtml::ajaxSubmitButton('ButtonName',Yii::app()->createUrl('advert/LoadAdvertFromSay'),
- array(
- 'type'=>'POST',
- 'data'=> 'js:$("#dataContainer").serialize()',
- 'success'=>'js:function(string){ alert(string); }'
- ),array('class'=>'someCssClass',));
- ?>
- In this case, all input type elements in the element with id dataContainer would be submitted, and could be accessed via $_POST.
- Obviously, the JS could be more complicated, you could get values from certain elements, and build your own object, e.g.:
- 'data' => 'js:{"field1": $("#input1").val(), "pageTitle": $("title").text() }'
- 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