你好,我正在调用 Controller 以在我的基于 codeigniter 的应用程序中使用 AJAX 获取部分,该应用程序启用了 CSRF
我的ajax代码
$('#classes').change(function(){
$classes=$(this).val();
$.ajax({
type:"POST",
data:{
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>',
'class':$classes
},
url:"<?php echo base_url();?>index.php/admin/getsection/"+$classes,
success:function(return_data)
{
//alert(return_data);
$('#section').html('');
$('#section').html(return_data);
$('#section').val(section);
}
});
当我第一次调用 ajax 函数时,它会运行完美。但是当我再次运行相同的函数时,它会返回 403 forbidden 错误。
请指点我的做法
最佳答案
来自 the docs :
Tokens may be either regenerated on every submission (default) or kept the same throughout the life of the CSRF cookie. The default regeneration of tokens provides stricter security, but may result in usability concerns as other tokens become invalid (back/forward navigation, multiple tabs/windows, asynchronous actions, etc). You may alter this behavior by editing the following config parameter
$config['csrf_regenerate'] = TRUE;
将其设置为 FALSE。
关于php - Ajax CSRF 403 禁止代码点火器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32478355/