sub*_*bbu -2 javascript jquery wolfram-mathematica
我在Wolfram Mathematica中构建了一个Web应用程序,它在浏览器上直接显示数据库数据.
我将我的应用程序放在Apache Tomcat中.
我想每15秒重新加载一次这个页面,因为如果你重新加载页面,我们将获得DB的更新数据.
我怎样才能做到这一点?
Guf*_*ffa 11
在页面的head部分添加这样的脚本:
<script type="text/javascript">
window.setTimeout(function(){ document.location.reload(true); }, 15000);
</script>
Run Code Online (Sandbox Code Playgroud)
该setTimeout方法将在15秒后开始回调,该reload方法将重新加载页面.该true参数使浏览器始终再次请求页面,而不是可能使用缓存版本.
那不好不是吗?在15秒内重新加载一次页面将彻底破坏用户体验.用户将无法在15秒内正确读取页面以获取上下文.
为什么不使用ajax获取结果来在15秒内更新包含数据的容器一次?通过这个,你将给用户更新的信息.
$.ajax({
type: "POST",
url: "some.php", //some server method which will get u new data from database
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
var i= 0;
for(; i< msg.d.length; i++)
{
$("#container").append(msg.d[i]);
}
});
Run Code Online (Sandbox Code Playgroud)
您在#container哪里有数据代表.
AJAX文档:http://api.jquery.com/jQuery.ajax/
| 归档时间: |
|
| 查看次数: |
20037 次 |
| 最近记录: |