Codeigniter ajax CSRF problem

前端 未结 7 2117
醉话见心
醉话见心 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:26

    As others say - you have to post the CSFR token name and its value with the AJAX request parameters. Here is a simple solution to append it automatically to every AJAX request.

    Here is what I put on my main view, so this code is on every page before loading the other javascript files:

       
       
      
    
    

    And here is a part of a javascript file that I include on every page:

    $(function() {
        // Attach csfr data token
        $.ajaxSetup({
           data: csfrData
        });
    });
    

提交回复
热议问题