Regenerate CRSF token codeigniter on submit Ajax

后端 未结 5 610
遥遥无期
遥遥无期 2021-01-07 04:46

Hi I am looking for the process of regeneration of csrf token in codeigniter when ever a form is submitted using ajax. I want the token to be regenerated without page refres

5条回答
  •  遥遥无期
    2021-01-07 05:09

    The solution that worked for me is that for subsequent ajax post when CSRF is enabled for every request is to make a GET request in AJAX Success when request fails because token has expired. Then have a hidden field that continue to be updated with latest token and if at the time of making request it has expired you make a GET REQUEST to fetch latest TOKEN and then evoke click event on function that submits form or function making POST request which means the function has to be passed "this" or ID as part of parameter.This makes the user not to realize the process of renewing token in the background

提交回复
热议问题