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

后端 未结 8 542
北恋
北恋 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:14

    Note: See the answer from Skullcrasher to fix the issue in the correct way as my answer suggests disabling the Cross-Site Request Forgery.


    You have a problem with enableCsrfValidation. To read more about it you can read here.

    To disable CSRF, add this code to your controller:

    public function beforeAction($action) {
        $this->enableCsrfValidation = false;
        return parent::beforeAction($action);
    }
    

    This will disable for all actions. You should probably, depending on the $action, disable it only for specific actions.

提交回复
热议问题