Codeigniter ajax CSRF problem

前端 未结 7 2073
醉话见心
醉话见心 2020-11-27 06:08

I\'ve made a simple autoload function that loads content when you scroll down on a website. However, there seems to be a few problems when i enable CSRF protection in Codeig

相关标签:
7条回答
  • 2020-11-27 06:51

    Previous suggestions work great, but rather than using a variable that you can apply in every data-post, I find it simpler to use the ajax-setting to automatically apply this token to every post:

    $(document).ajaxSend(function(elm, xhr, s){
            if(s.data){
                s.data += '&';
            }
            s.data += '<?php echo $this->security->get_csrf_token_name(); ?>=<?php echo $this->security->get_csrf_hash(); ?>';
        }); 
    

    (works with jquery-1.9.1. I'm not sure about other jquery-versions)

    0 讨论(0)
提交回复
热议问题