HTML page Refresh

Source: Internet
Author: User
Tags jquery library

JS ScriptMethod 1 setinterval function

Timed local Refresh uses the SetInterval method inside jquery, which requests data at intervals and then returns the request result to the front-end HTML implementation refresh.

SetInterval method Two parameters, the first is to set the function name of a timed execution, the second is the time.

<Scriptsrc= "Https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></Script><Script>$(function()
{GetData (); SetInterval (function() {getData (); }, the); });

function GetData () {$.getjson ("/BLOOD/PRESSURE/1", function(data) {if ( $ ==Data.code) {$ ("#systolic"). Text (data.data.systolic); $("#diastolic"). Text (data.data.diastolic); $("#pulse"). Text (Data.data.pulse); } });

$ ("#date"). Text ((new date ()). ToString ()); };
</Script>
Funciton GetData () {var url = "Request Address"; var data = {Type:1}; $.ajax ({  type: "Get",  async:false,//sync request  URL: URL,  data:data,  timeout:1000,  success:function (dates) {  //alert (dates);  $ ("#mainContent"). HTML (dates);//To refresh the div  },  error:function () {        //alert ("Failed, please try again later!") ");      } });

Also note that setTimeout () does not refresh the page regularly. After the SetTimeout () is set, it is refreshed only once and needs to be set again before it is refreshed again.

eg. setTimeout (function() {location.reload ()},+); // Specify refresh once after 1 seconds

Method 2

Occasionally, I need some kind of mechanism to constantly refresh the page to provide a real-time dashboard. If I can only refresh a particular part of the page, it will be great, for example: the traffic lights on the dashboard show the system status.

It is very easy to refresh only part of the page by using the jquery JavaScript library. Once we include the jquery library on our page, we only need 1 rows of

JavaScript gets its work:

<script src= "/js/jquery-1.3.2.min.js" type= "Text/javascript" ></script>

So we just put our page into this little JS code snippet to refresh everything inside the content ID tag, let's say every 5 seconds:

SetInterval (function () {  $ ("#content"). Load (location.href+ "#content >*", "");}, 5000);

That's it!! Therefore, it is very easy to complete some real-time monitoring behavior, just that line of code. There is no more strange meta refresh tag or iframe in a workaround, in a Web application.

Every 5 seconds, we will refresh the contents of the same URL and all elements that reside in the element ID as content: content.

Page Overall Refresh

1. Automatic page Refresh Note: 10 refers to the refresh of the page every 10 seconds.

<http-equiv= "Refresh" content= "Ten">    

2. Jump to the specified page

<http-equiv= "Refresh" content= "10;url=http://www.51jfgou.com">  

Reference articles

Several methods for automatic refresh of 1.html page

2. jquery Implement timed Refresh function code

3. How to refresh the page regularly

HTML page Refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.