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

后端 未结 8 538
北恋
北恋 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

    Use:

    var csrfToken = $('meta[name="csrf-token"]').attr("content");
    $.ajax({
        url: 'request',
        type: 'post',
        dataType: 'json',
        data: {param1: param1, _csrf : csrfToken},
    });
    

    More detail: Yii2: Using csrf token

提交回复
热议问题