tp5 ajax异步删除缓存

第一步:先贴出官网的解决方法清除缓存

 

清除模版缓存 不删除cache目录
/
public function clear_sys_cache() {
Cache::clear();
$this->success( '清除成功', 'index/index' );
}
/*
清除模版缓存 不删除 temp目录
/
public function clear_temp_ahce() {
array_map( 'unlink', glob( TEMP_PATH.DS.'/*.php' ) );
$this->success( '清除成功', 'index/index' );
}
/**

清除日志缓存 不删出log目录
/
public function clear_log_chache() {
$path = glob( LOG_PATH.'/' );
foreach ($path as $item) {
array_map( 'unlink', glob( $item.DS.'.' ) );
rmdir( $item );
}
$this->success( '清除成功', 'index/index' );
}

 

 

 

结合自己的ajax

 

js页面

<script type="text/javascript">

function clear_cache()
        {
            var xhr =new XMLHttpRequest();
            xhr.onreadystatechange =function(){
                if(xhr.readyState==4)
                {
                    alert(xhr.responseText);
                    // document.getElementById('id_check_stu').innerHTML=xhr.responseText;
                }
            }
            /*获得输入学号/工号的信息*/
            // var ming = document.getElementById('form-first-name').value;

            /*thinkphp框架所以操作都是控制器和操作方法的结合*/

            xhr.open('get','{:url('Common/clear_cache')}');
            xhr.send(null);
            
        }
</script>

 

html页面

   <button style="margin-top:8px;" type="button" tooltip="添加图片" class="btn btn-sm btn-azure btn-addon" onClick="clear_cache()"> </i> 清除缓存
                    </button>

控制器

Public function clear_cache()
    {
        // echo "1";
        // exit;
        // dump(TEMP_PATH);
        // dump(glob( TEMP_PATH.DS.'.php' ));
        array_map( 'unlink', glob( TEMP_PATH.DS.'/*.php' ) );
       Cache::clear();
       
       echo "清除成功";

       exit;
       

    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值