How to include CSRF from Codeigniter into ajax data

前端 未结 6 2030
傲寒
傲寒 2020-12-10 18:04

I am trying to pass some data into my Controller, but I\'m getting a 500 error. After some research, I discovered that it\'s caused by the CSRF token not being sent.

6条回答
  •  青春惊慌失措
    2020-12-10 18:36

    CI stores csrf in cookie and you can fetch it from there:

    var csrf = $.cookie('csrf_cookie_name');
    

    The downside of this method is that jQuery doesn't natively provide cookie access. So you will need a jquery plugin.

提交回复
热议问题