Home > Web Front-end > JS Tutorial > How to achieve flicker-free scheduled page refresh with Ajax

How to achieve flicker-free scheduled page refresh with Ajax

php中世界最好的语言
Release: 2018-04-04 14:29:12
Original
2046 people have browsed it

This time I will show you how Ajax can achieve flicker-free scheduled refresh page effect. What are the precautions for Ajax to achieve flicker-free scheduled refresh page effect. Here is a practical case, let’s take a look.

In web development, we often need to refresh a page regularly:

1. To maintain session value or check whether the session value is empty (for example, to prevent the same user from logging in repeatedly);

2. Implement real-time in-site text messages;

3. Update page data regularly, etc. However, when we search on the Internet, we will find that there are many ways to refresh the page regularly. The simplest is to add the following code between the

tags:

in < Add code between head>

tags to achieve regular refresh. I have tested this code and it can achieve the effect

Description: The value of content represents the interval between page refreshes, in seconds.

The value of URL specifies the page to be refreshed

Another way is to use JavaScript to refresh the page regularly

JavaScript to refresh the page regularly, I don’t have this code After testing,

<script> 
var limit=":" 
if (document.images){ 
var parselimit=limit.split(":"); 
parselimit=parselimit[]*+parselimit[]*; 
} 
function beginrefresh(){ 
if (!document.images) 
return; 
if (parselimit==) 
window.location.reload(); 
else{ 
parselimit-=; 
curmin=Math.floor(parselimit/); 
cursec=parselimit%; 
if (curmin!=) 
curtime=curmin+" min "+cursec+" sec "; 
else 
curtime=cursec+" sec "; 
window.status=curtime; 
setTimeout("beginrefresh()",); 
} 
} 
window.onload=beginrefresh;
</script>
Copy after login

is added to the middle of the body. Here is 0:10 for 10 seconds. It can be customized.

I believe you have mastered the method after reading the case in this article. More exciting Please pay attention to other related articles on php Chinese website!

Recommended reading:

How to use Ajax cross-domain request

Jump to the login page immediately after Ajax+Session fails

The above is the detailed content of How to achieve flicker-free scheduled page refresh with Ajax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template