Getting bad request (#400) on Ajax calls using Yii 2

后端 未结 8 456
北恋
北恋 2020-12-29 08:39

This is my code:

$(document).on(\'change\', \'#tblhotel-int_zone_id\', function(e){
    var zoneId = $(this).val();
    var form_data = {
        zone: zoneI         


        
相关标签:
8条回答
  • 2020-12-29 09:18

    This works. Change the csrfParam with your own in Config/main.php

    'components' => [
        'request'=>[
            'csrfParam'=>"othername"
        ],
        ...
    

    Remember that you must include in your requests the token with the same name as you defined in config.

    0 讨论(0)
  • 2020-12-29 09:19

    You need to disable CSRF validation in the before action function:

    public function beforeAction($action) {
        if($action->id == "action name need to disable")
            $this->enableCsrfValidation = false;
        return parent::beforeAction($action);
    }
    

    Or using the GET method.

    0 讨论(0)
提交回复
热议问题