Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the Ajax fetching page is cached

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to solve the problem of Ajax getting pages cached", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the problem that Ajax fetch pages are cached".

In this case, the native cache is checked first when fetching for AJAX, and if the native cache already has the same content, the remote server is not accessed. This operation can improve the speed and reduce the pressure on the server. But the disadvantages are also obvious.

In order to solve this problem. We must add an extra parameter to the fetch page. The easier way is to use a random number.

Examples are as follows

The copy code is as follows:

The parameter function idCheck () {/ / calls the function

Var f = document.modify_form

Var book_num = f.book_num.value

If (book_num== "") {

Window.alert ("Book number cannot be empty")

F.book_num.focus ()

Return false

}

/ / add a random number /

Var number = Math.random ()

Number = number * 1000000000

Number = Math.ceil (number)

/ /

Send_request ('get_book.php?book_num='+book_num+'&ranum='+number); / / the word "ranum=number" after it is added.

}

This avoids the problem that the page with the same parameters returns the same content.

Another method is to add code to the called page to prohibit the page from being cached

Htm web page

The copy code is as follows:

Or

Asp web page

The copy code is as follows:

Response.expires=-1

Response.expiresabsolute=now ()-1

Response.cachecontrol= "no-cache"

Php web page

The copy code is as follows:

Header ("expires:mon,26jul199705:00:00gmt")

Header ("cache-control:no-cache,must-revalidate")

Header ("pragma:no-cache")

Jsp web page

The copy code is as follows:

Response.addHeader ("pragma", "no-cache")

Response.addHeader ("cache-control", "no-cache,must-revalidate")

Response.addHeader ("expires", "0")

At this point, I believe you have a deeper understanding of "how to solve the problem of Ajax getting pages cached". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report