2017-05-26 22 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

相關問題