如何为此代码添加自动刷新?
How to add auto-refresh to this code?
我叫约翰。 (是的,我知道非常有用的信息 :))我在 php 中创建了一个新的统计数据,我的 Javascript 代码看起来像
var req;
function hide() {
for(var i=0; i<arguments.length; i++) {
element = document.getElementById(arguments[i]);
if (element) {
element.style.visibility = 'hidden';
}
}
}
function show() {
for(var i=0; i<arguments.length; i++) {
element = document.getElementById(arguments[i]);
if (element) {
element.style.visibility = 'visible';
}
}
}
function loadXMLDoc(url) {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
hide('lastposts');
show('lastposts_update');
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
hide('lastposts');
show('lastposts_update');
}
}
}
function processReqChange() {
if (req.readyState == 4) {
element = document.getElementById('lastposts_text');
if (element) {
if (req.status == 200) {
element.innerHTML = req.responseText;
} else {
element.innerHTML = "Error " + req.status + "<br />" + req.statusText;
}
}
hide('lastposts_update');
show('lastposts');
} else {
var status_message = new Array(
"The query is not initialized",
"The query is created",
"The query is sent",
"The query is processed"
);
element_status = document.getElementById('status');
if (element_status) {
element_status.innerHTML = status_message[req.readyState];
}
}
}
和HTML输出
<div id="lastposts_update" style="visibility: hidden;">
<img src="images/refresh.gif" alt="wait">
<span id="status"></span>
</div>
<div id="lastposts" style="z-index: 2;">
<a href="" onclick="loadXMLDoc('{URL}'); return false;">
<img src="images/refresh.gif" alt="refresh" border="0"></a>
<span id="lastposts_text">
{IMPORT_NEW_STATISTICS}
</span>
</div>
如何修改此代码并添加自动刷新和删除手动刷新?
你能帮助我吗?我将不胜感激
这是类似的QA Auto refresh code in HTML using meta tags
尝试把下面的代码
<meta http-equiv="refresh" content="5">
进入 HTML header 标签。
我叫约翰。 (是的,我知道非常有用的信息 :))我在 php 中创建了一个新的统计数据,我的 Javascript 代码看起来像
var req;
function hide() {
for(var i=0; i<arguments.length; i++) {
element = document.getElementById(arguments[i]);
if (element) {
element.style.visibility = 'hidden';
}
}
}
function show() {
for(var i=0; i<arguments.length; i++) {
element = document.getElementById(arguments[i]);
if (element) {
element.style.visibility = 'visible';
}
}
}
function loadXMLDoc(url) {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
hide('lastposts');
show('lastposts_update');
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
hide('lastposts');
show('lastposts_update');
}
}
}
function processReqChange() {
if (req.readyState == 4) {
element = document.getElementById('lastposts_text');
if (element) {
if (req.status == 200) {
element.innerHTML = req.responseText;
} else {
element.innerHTML = "Error " + req.status + "<br />" + req.statusText;
}
}
hide('lastposts_update');
show('lastposts');
} else {
var status_message = new Array(
"The query is not initialized",
"The query is created",
"The query is sent",
"The query is processed"
);
element_status = document.getElementById('status');
if (element_status) {
element_status.innerHTML = status_message[req.readyState];
}
}
}
和HTML输出
<div id="lastposts_update" style="visibility: hidden;">
<img src="images/refresh.gif" alt="wait">
<span id="status"></span>
</div>
<div id="lastposts" style="z-index: 2;">
<a href="" onclick="loadXMLDoc('{URL}'); return false;">
<img src="images/refresh.gif" alt="refresh" border="0"></a>
<span id="lastposts_text">
{IMPORT_NEW_STATISTICS}
</span>
</div>
如何修改此代码并添加自动刷新和删除手动刷新? 你能帮助我吗?我将不胜感激
这是类似的QA Auto refresh code in HTML using meta tags
尝试把下面的代码
<meta http-equiv="refresh" content="5">
进入 HTML header 标签。