这是ajax版本,当文本文件内部发生变化时会弹出警报 它运作良好。但我也想在弹出窗口时发出警报 我试过并搜索了几个小时,但我找不到哪个与我的ajax脚本一起工作。
<audio id="audiotag1" src="Ring04.wav" preload="auto"></audio>
<script language="javascript">
var previous = "";
setInterval(function() {
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (ajax.readyState == 4) {
if (ajax.responseText != previous) {
document.getElementById('audiotag1').play();
sleep(1);
alert("file changed!");
previous = ajax.responseText;
}
}
};
ajax.open("POST", "xxx.txt", true); //Use POST to avoid caching
ajax.send();
}, 3000);
</script>