Problems with Ajax clearing cache

Source: Internet
Author: User

When using AJAX for Web development, there are often some puzzling questions.

For example, the first time the AJAX request is normal, and the second time why it is not normal, and often appear in the first request the same result.

In fact, this is because the first time the AJAX request is actually sent to the server, and the second time is not really sent to the server, but from the IE cache read.

So how do we solve this problem?

The simple way to do this is to make the URL of the AJAX request different every time.

Workaround: Add a random number after the URL of the AJAX request:? Ram=math.random ()

Example: The URL to be requested is "ajax.aspx"

Then instead: "ajax.aspx?ram=" + math.random ();

This completely avoids errors caused by Ajax reading from the cache.

The second kind of clearing cache:

Response.ExpiresAbsolute = DateTime.Now.AddDays (-1);

response.expires=0;

Response.cachecontrol= "No-cache";

Problems with Ajax clearing cache

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.