我在 fwrite 后被迫刷新文件 (html) 以显示更改

I am Forced To Refresh File (html) After fwrite to Show Changes

总览:

我正在我的服务器 (http://example.com/stock_order.html) 上的一个文件中写一个简单的 html table,然后将文件 url 返回到 Javascript 使用 ajax 在新 tab.this 中打开是我的代码:

PHP:

   $newfile = fopen($_SERVER['DOCUMENT_ROOT']."/stock_order.html","w+") or    die("Unable to open file!");
    $txt ='';
    $txt .='Here i put table data'; 
    fwrite($newfile, $txt);
    fclose($newfile);
    $link = "http://www.webber.solutions/stock_order.html";
    echo $link;

JS:

  $.ajax({
 url: "index.php?route=sale/print/printStock&token=<?php echo $token; ?>",
 type: "post",
 data: {ids:ids},
 cache: false,
 }).done(function( data ) {
       // using url from php i open a new tab here
 window.open(data , '_blank');
 });

问题: 数据正在文件中正确写入,但有一些延迟,这意味着当重定向到 html 文件时,文件内容是旧数据,新写入的数据仅在我手动刷新页面时显示。

我试过在fwrite后延迟1-2秒,还是没有变化。

这个服务器相关吗?还是我的代码有问题? 请帮忙

这很可能是浏览器缓存,而不是文件 "old" 尝试将 url 更改为:

echo "http://www.webber.solutions/stock_order.html?t=".time();

或类似的东西以避免缓存

您可以在打开 window 后刷新页面,如下所示:

$.ajax({
    url: "index.php?route=sale/print/printStock&token=<?php echo $token; ?>",
    type: "post",
    data: {ids:ids},
    cache: false,
    }).done(function( data ) {
       // using url from php i open a new tab here
    window.open(data , '_blank');
    document.location.reload(true);
    });