Codeigniter ajax CSRF problem

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

    Basically what you need to do is get the expected csrf value from the cookie (named 'ci_csrf_token' by default), then post it along with your other data.

    You would need to modify this line:

    $.post(baseurl + 'ajax/images',{'id' : ID}, function(data) {
    

    to:

    $.post(baseurl + 'ajax/images',{'id' : ID,'ci_csrf_token' : $.cookie('ci_csrf_token')}, function(data) {
    

    Might need to install the cookie addon (I'm not really sure; I use mootools). Here is more information: http://aymsystems.com/ajax-csrf-protection-codeigniter-20.

提交回复
热议问题