Jonnny
Jonnny

Reputation: 5039

Yii Ajax request CSRF can not be verified

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
},

Upvotes: 4

Views: 6466

Answers (1)

Cherif BOUCHELAGHEM
Cherif BOUCHELAGHEM

Reputation: 1136

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)`

Upvotes: 4

Related Questions