Yii Ajax request CSRF can not be verified

不问归期 提交于 2019-12-10 15:18:32

问题


I use a few different AJAX calls in one of my pages through a couple of different methods.

  1. CHtml::link()
  2. CHtml::ajax()
  3. Within CGridview

Since enabling CSRF I'm having difficulty verifying the token. What is the correct way? I've read a few posts, but struggling to implement. For instance in CHtml::link() I've tried:

'data' => "Yii::app()->request->csrfTokenName = Yii::app()->request->csrfToken",

and also within CGridview:

data: {
    Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken
},

回答1:


1- Fot ajax you have ajax, ajaxLink and ajaxButton not just link.

2- CSRF token works when you use POST request

3- Add CSRF token like this:'data'=>array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken)`



来源:https://stackoverflow.com/questions/18597894/yii-ajax-request-csrf-can-not-be-verified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!