最近在作一個網站,須要用到實時刷新,因而就學習了一下有關資料,跟你們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();
- }
- }
- });