[英]How do I change the headers that PHP sends when using file_get_contents on an external URL?
[英]How do I refresh an HTML file when the contents of a different file change?
我遇到這樣的情況:設備使用PHP訪問簡單的MySQL數據庫。 當我進行搜索時,結果將寫入HTML文件中。
我還有第二個設備(非常基本的Android平板電腦)已打開此HTML文件。 使用live.js可以在內容更改時刷新。 我需要的是:一條靜態消息,上面寫着“等待搜索結果”之類的內容,並且僅在頁面內容更改結果時才顯示...
這樣的事情:在平板電腦上加載1.html(等待搜索結果)。 當2.html頁的內容發生更改(有搜索查詢)時,將其顯示(2.html)。 按下按鈕(用戶輸入)后,讓我們回到1.html,等待頁面2.html的內容再次更改。
僅使用live.js時,我只能監視當前打開的文件...
關於如何實現此目標的任何想法嗎? 謝謝你
[編輯-已解決]我的工作方式是這樣的:平板電腦的用戶按下按鈕時,它將運行PHP腳本,該腳本將文件內容(先前的搜索結果)替換為“等待結果”文本。 當然,它的頭部帶有live.js,並且在進行新搜索時,頁面會重新加載新搜索結果。
這比我認為的要容易得多。
PHP腳本:
<?php
ob_start();
$myFile = 'ana.html';
unlink($myFile);
$fh = fopen($myFile, 'w') or die ("can't open file");
$stringData =
'<html>
<head>
<title>Rezultatele cautarii</title>
<link rel="stylesheet" href="style.css">
<script src="live.js"></script>
</head>
<body>
<h1 class="button">Asteptam cererea</h1>
</body>
</html>';
fwrite($fh, $stringData);
fclose($fh);
header('Location: '.$myFile);
die();
?>
你的意思是這樣嗎?
document.write('<div id="loading"><br><br>Please wait...</div>');
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
document.getElementById("loading").style.display="none";
});
我想您可以在JavaScript中運行setInterval(),然后獲取頁面內容,就像以前的間隔一樣,然后在PHP中使用校驗和進行比較? 或者只是逐字母比較它。 現在太累了,無法編寫代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.