问题描述
这是我的code
$(document).on('change', '#tblhotel-int_zone_id', function(e){
var zoneId = $(this).val();
var form_data = {
zone: zoneId
};
$.ajax({
url: "state",
type: "POST",
data: form_data,
success: function(response)
{
alert(response);
}
});
});
这显示错误的请求(#400):无法验证数据提交。而且已经有< = HTML :: csrfMetaTags()>
任何建议?
This shows Bad Request (#400): Unable to verify your data submission.And already having <?= Html::csrfMetaTags() ?>
Any suggestion?
推荐答案
看到Skullcrasher的答案,这样做在一个更合适的方式。
SEE THE ANSWER FROM Skullcrasher TO DO THIS IN A MORE PROPER WAY.
您有enableCsrfValidation一个问题。想了解更多关于它,你可以阅读<一个href="http://www.yiiframework.com/doc-2.0/yii-web-controller.html#$enableCsrfValidation-detail">here.
You have a problem with enableCsrfValidation. To read more about it you can read here.
要禁用CSRF添加此code到控制器:
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.
这篇关于Yii2 - 获取错误的请求(#400)上的Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!