最近在作一个网站,须要用到实时刷新,因而就学习了一下有关资料,跟你们share一下。javascript
1)其实刷新不用js也能够实现。单纯的html能够用meta标签搞定html
- <meta http-equiv="refresh"content="10;url=xxx.com">
- //表示间隔10秒后刷新,即打开网页后10秒就跳转到了xxx.com中
2)js的话,有一个reload的函数和navigate的函数能够实现刷新整个页面java
- <script language=''javascript''>
- window.location.reload(true);
- </script>
- //若是是你要刷新某一个iframe就把window给换成frame的名字或ID号
- //navigate函数是个跳转函数,若是你给函数传参为自身的url,等于从本页面跳到了本页面,也实现了刷新的效果。
- <script language=''javascript''>
- window.navigate(”localUrl");
- </script>
3)实现定时刷新ajax
- <script>setTimeout("location.href='url'",2000)</script>
- //url是要刷新的页面URL地址
- //2000是等待时间=2秒,
4)jsp中定时刷新jsp
- <% response.setHeader("refresh","1"); %>
- //每一秒刷新一次
5)js+ajax局部刷新:ide
- setTimeout(function() {
- Push();
- },
- 200);//setTimeout 程序执行后200毫秒执行push,可是仅此一次。execute the function push only one time after the program began to work
- setInterval(function() {
-
- Push();
-
- },
- 3000);//三秒后执行 execute it after 3 seconds
-
- /*请求函数的ajax*/
-
- function Push() {
-
-
- $.ajax({
-
- type: "POST",
- url: "url.jsp",//须要跳转到的界面 the page you want to post data
- data: {
- data: data//要传给后台的数据 the data you should send to background
- },
- beforeSend: function() {},//在发送以前你能够进行相关操做 what you want to do before send
- success: function(data) {
- //须要执行的操做 execute it
- }else {
- $(".tongzhi").html(0).hide();
- }
- }
- });