2017-05-26 17 views
0

总观后:我不得不刷新文件(HTML)fwrite来显示更改

我写我的服务器(http://example.com/stock_order.html)在一个文件中一个简单的HTML表格,然后返回文件的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:

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

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

我试图把fwrite延迟1-2秒后仍然没有改变。

是否与此服务器相关?或者我的代码有问题? 请帮助

回答

0

它最有可能是浏览器的缓存,而不是文件的“年老”尝试改变网址为这样:

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

或相似,以避免高速缓存的东西

+0

,像变魔术一样,谢谢你 –

0

可以刷新后像下面打开的窗口页面:

$.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); 
    }); 
+0

谢谢 这是一个缓存的问题,容易使lved –

+0

哦,没问题... – lalithkumar

相关问题