我有以下代码在我的页面上显示一个php文件。但是我希望有人可以帮助我,使代码每300秒刷新一次
httpRequest("recent-widget.php", showrecent);
function showrecent(WIDGET){
d = document.getElementById('recent-widget');
d.innerHTML = WIDGET;
}
function httpRequest(url, callback) {
var httpObj = false;
if (typeof XMLHttpRequest != 'undefined') {
httpObj = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try{
httpObj = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try{
httpObj = new ActiveXObject('iMicrosoft.XMLHTTP');
} catch(e) {}
}
}
if (!httpObj) return;
httpObj.onreadystatechange = function() {
if (httpObj.readyState == 4) { // when request is complete
callback(httpObj.responseText);
}
};
httpObj.open('GET', url, true);
httpObj.send(null);
}
最佳答案
只需使用setInterval
每300000毫秒重复一次您在顶部进行的通话。例如
setInterval(function() {
httpRequest("recent-widget.php", showrecent);
}, 300000);
关于javascript - 每300秒执行一次Javascript运行脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17347709/