问题描述
我希望我的代码运行无限循环,第一次读取 data.xml 文件,然后仅在每次该文件发生更改时读取。
这是我的代码,它可以在文件准备好时获取,但无法区分该文件是否与上一次发生变化。
我希望我的代码更高效,以减少无用的流量,如果该文件未更改,则不会一遍又一遍地读取同一个文件。
任何帮助表示赞赏。
谢谢。
马里奥。
<html>
<body>
<script>
const interval = 3000;
setInterval(function(){
function_01();
},interval);
function function_01() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// i wish my code to run function_02 only if data.xml is changed from prevIoUs time
function_02(this);
}
};
xmlhttp.open("GET","data.xml",true);
xmlhttp.send();
}
function function_02(xml) {
var x,i,xmlDoc,txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("ARTIST");
for (i = 0; i< x.length; i++) {
tmp = x[i].childNodes[0].nodeValue
console.log(tmp)
}
}
</script>
</body>
</html>```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)