2,131   CodeIgniter PHP

原因分析:
CI开启了csrf,在每次ajax请求后,会刷新hash值,但是前端还是旧的hash值,所以导致第二次ajax请求时失效,尤其是表单提交的时候

 <input type="hidden" name="csrf_test_name" value="51a73f2a9a964ad3f54a54a50024b45a" style="display:none;">

解决方法:
在ajax请求时,服务端获取新的hash值,并返回给前端,更新hash值,这样第二次ajax请求时就有效了

			
$csrf = array(
    'name' => $this->security->get_csrf_token_name(),
    'hash' => $this->security->get_csrf_hash()
);
$output['csrf'] = $csrf;



Leave a Reply

Your email address will not be published. Required fields are marked *