php - Ajax CSRF 403 禁止代码点火器

标签 php jquery ajax codeigniter csrf

你好,我正在调用 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/

相关文章:

javascript - 我不确定我的 ajax 导航是否正常工作

php - 具有多个字段的 MySql Distinct

php - 不使用 PHP 重定向的 POST

php - 动态 MySQL 查询 : Join results from numerous tables

jquery从右边滑出div

c# - 如何在 .NET Webforms 中使用 Jquery AJAX 将数据发布到 MySQL

php - 检测 DateTime 对象中是否指定了时间

javascript - 等到动画结束后再替换div内的数据

javascript - jquery addClass 添加子类不起作用

javascript - 使用 ajax 时数据表搜索输入的 Keyup 事件不会触发