如何检测网页中的更改并使用Javascript播放声音?
现在我有了一个javascript代码,它每2秒刷新一个网页,以检查数据库是否有任何更新 我希望它能在网页显示新内容时播放声音 以下是html文件:如何检测网页中的更改并使用Javascript播放声音?,javascript,jquery,Javascript,Jquery,现在我有了一个javascript代码,它每2秒刷新一个网页,以检查数据库是否有任何更新 我希望它能在网页显示新内容时播放声音 以下是html文件: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">&
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(function() {
$.ajaxSetup ({
cache: false
});
var auto_refresh = setInterval(function () {$('#loading').load('index.php').fadeIn("slow");}, 2000);
});
</script>
</head>
<body>
<div id="loading"></div>
</body>
</html>
$(函数(){
$.ajaxSetup({
缓存:false
});
var auto_refresh=setInterval(函数(){$('#load').load('index.php').fadeIn(“slow”)},2000);
});
我是Javascript新手我认为您需要的是像HTTP ETag这样的自定义实现。 应该是这样的: 从PHP脚本发送的html中提取版本号,将此版本号传递给每个ajax请求,服务器将检查这两个版本并向客户端提供正确的响应 如果服务器以 1) http状态代码200=>网页已更改=>播放声音
2) http状态代码304=>网页未更改以json格式从服务器获取响应,如果有任何更改,则在从服务器获得成功响应时,使用HTML音频标记播放soundplay sound。