In the (ASP/PHP/JSP/html/js) method to prohibit ajax cache collection, jsajax

Source: Internet
Author: User

In the (ASP/PHP/JSP/html/js) method to prohibit ajax cache collection, jsajax

Ajax cache is good, but it also has some disadvantages. caching sometimes leads to misoperations and affects user experience. If your WEB project does not require ajax caching, you can disable ajax caching in the following ways.

1. Disable ajax caching in ASP:

'At the beginning of ASP Web Page

Response.expires=0Response.addHeader("pragma","no-cache")Response.addHeader("Cache-Control","no-cache, must-revalidate")

2. Disable Ajax caching in PHP:

// Header ("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); header ("Cache-Control: no-cache, must-revalidate "); header ("Pragma: no-cache ");

3. Disable ajax caching in JSp:

 

// Put it at the beginning of the JSP page, response. addHeader ("Cache-Control", "no-cache"); response. addHeader ("Expires", "Thu, 01 Jan 1970 00:00:01 GMT ");

4. Force update by adding random characters to the webpage: For example

var url = 'http://url/';url += '?temp=' + new Date().getTime();url += '?temp=' + Math.random();

5. If it is static HTML, you can add an HTTP headers header to disable caching. For example:

<meta http-equiv="pragma" content="no-cache" /><meta http-equiv="Cache-Control" content="no-cache, must-revalidate" /><meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:01 GMT" /><meta http-equiv="expires" content="0" />

6. You can add the following code to prohibit ajax caching before XMLHttpRequest sends a request:

XMLHttpRequest.setRequestHeader("If-Modified-Since","0");XMLHttpRequest.send(null);

VII. jQuery ajax Load disabled

JQuery provides a method to prevent ajax from using the cache. You can solve the problem by adding the following statements to the javascript file of the head.

$. AjaxSetup ({cache: false // disable the corresponding AJAX cache });


Summary, but now jquery ajax is used. If you do not want to cache, you can directly set cache: false to solve the problem of post, get, and other data submission methods.


How to Use js or ajax to prevent static files such as jsp pages and xml contained in pages from being cached?

Another method is
Add a random number to the end of the request url
For example, request a. aspx
You can write $. get ("a. aspx? "+ Math. random (), function (data ){});
This will not be cached.

Do you have to master all front-end technologies such as js jsp css jsp jquery html ajax before you can become a J2EE programmer in the company?

You prefer visual development. I don't know if you are talking about visualization during development or development of visual components.
However, companies generally do not require programmers to be very good at the front-end, so they will be able to understand it.

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.