Yii form ajax request CSRF token error

时间:2015-06-30 13:30:25

标签: php ajax yii csrf

I trying to get list of districts depends on country, but when I changed country I got error:

The CSRF token could not be verified.

Code:

<?php
echo $form->dropDownList(
        $generalInfoForm,
        'country',
        CHtml::listData(Countries::model()->findAll(array('order' => 'name')), 'code', 'name'),
        array(
            'prompt' => '(Select country)',
            'ajax' => array(
                'type'=>'POST',
                'url'=>Yii::app()->createUrl('//user/auth/loadcities'),
                'update'=>'#city_name',
                'data'=> array(
                    'YII_CSRF_TOKEN' => Yii::app()->request->csrfToken,
                    'country_id'=>'js:this.value'
                ),
            )
        ),
        array(
            'class' => 'form_input_password bx-def-font',
            'id' => 'general_info_country',
            'placeholder' => Yii::t('UserModule.views_auth_login', 'password')
        )
);
?>

Any ideas? Thanks!

1 个答案:

答案 0 :(得分:0)

通过更改&#39; YII_CSRF_TOKEN&#39;解决到&#39; CSRF_TOKEN&#39;