php - Ajax call crash on CodeIgniter - CSRF Error 403 -
i'm trying perform ajax calls within codeigniter. had searched before, when csrf protection active, hash (randomly generated) must submitted each request server.
in research found following code hash sent along other data through ajax request:
$.ajaxsetup({ data: { arquivo_facil_tk: $.cookie('arquivo_facil_co') } });
so got positive result on first call right after page loaded. attempt second call, error 403. found option of adding code snippet each ajax call make, software performs several calls, becomes unfeasible , rude.
how fix this? tried using beforesend event got same error.
rather using ajaxsetup
include csrf token along data
in actual ajax call so:
data: {var: value, arquivo_facil_tk: $.cookie('arquivo_facil_co')}
or if you're serializing forms simply:
data: $(this).serialize() + '&arquivo_facil_tk=' + $.cookie('arquivo_facil_co')
Comments
Post a Comment