使用的框架版本:Thinkphp3.2.5
找到文件ThinkPHP\Library\Think\Controller.class.php
头部修改
namespace Think;
namespace Think;
use Behavior\TokenBuildBehavior;
查找dispatchJump
if (true === $ajax || IS_AJAX) {
// AJAX提交
$data = is_array($ajax) ? $ajax : array();
$data['info'] = $message;
$data['status'] = $status;
$data['url'] = $jumpUrl;
$data['token_key'] = $token[1];
$data['token_Value'] = $token[2];
$this->ajaxReturn($data);
}
修改为
if (true === $ajax || IS_AJAX) {
// AJAX提交
/******************************/
$tokenduixiang=new TokenBuildBehavior();
$token=$tokenduixiang->getToken();
/******************************/
$data = is_array($ajax) ? $ajax : array();
$data['info'] = $message;
$data['status'] = $status;
$data['url'] = $jumpUrl;
$data['token'] = $token[1]."_".$token[2];
$this->ajaxReturn($data);
}
找到文件
ThinkPHP\Library\Behavior\TokenBuildBehavior.class.php
private function getToken()
修改为
public function getToken()
ajax提交数据就可以看到新的token
紧接着自己在ajax回调中修改的值
<meta name="__token__" content="回调回来的token">
<input type="hidden" name="__token__" value="回调回来的token">
这样就可以ajax无刷新更新token
版权声明:若无特殊注明,本文皆为《xiaopang》原创,转载请保留文章出处。
本文链接:thinkphp3.2解决ajax无法刷新表单令牌token - https://cloud.tencent.com/developer/article/1552517
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有