1
我想通過Yii中的引導按鈕使用Ajax,並希望通過該Ajax調用傳遞文本字段值。如何在yii中通過引導按鈕調用ajax
這裏是按鈕代碼,我應該在哪裏放置此按鈕的Ajax代碼。
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD')); ?>
我想通過Yii中的引導按鈕使用Ajax,並希望通過該Ajax調用傳遞文本字段值。如何在yii中通過引導按鈕調用ajax
這裏是按鈕代碼,我應該在哪裏放置此按鈕的Ajax代碼。
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD')); ?>
試試這個
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD',
'ajaxOptions' => array(
'type' => 'Post',
'url' => $this->createURL('url'),
'data' => Yii::app()->request->csrfTokenName."=".Yii::app()->request->getCsrfToken()."&action=cancel",
'success'=>"js:function(vals){
}",
)
)); ?>
其他如:
$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'ajaxButton',
'label' => 'Label Here',
'type' => 'danger',
'icon' => 'play white',
...
'ajaxOptions' => array(
'success' => '...',
'error' => '...',
'beforeSend' => '...',
)
));
確定。但是這一行的意思是'data'=> Yii :: app() - > request-> csrfTokenName。「=」。Yii :: app() - > request-> getCsrfToken()。「&action = cancel」, – PhpCoder
跨站點請求僞造(CSRF)。你可以省略那個。爲了防止CSRF攻擊,遵守這樣的規則是很重要的,即GET請求只應允許檢索數據而不是修改服務器上的任何數據。對於POST請求,它們應該包含一些可以被服務器識別的隨機值,以確保表單被提交併且結果被髮回到同一個來源。 –
瞭解更多關於在yii中使用csrf令牌的信息,請查看此鏈接http://www.yiiframework.com/doc/guide/1.1/en/topics.security#cross-site-request-forgery-prevention –