Solve the problem that jquery ajax cannot obtain the latest data under IE (IE cache)

Source: Internet
Author: User

Today, I modified a bug and used ajax to query data. In Google's browser, I can get the latest data. In IE, I got old data, but I cannot get the latest data, I found the IE cache again.
It is found that the ajax request uses the get method. The URL of each request is the same. The IE browser has a special place. If the URL of each request is the same, the existing data in the cache is displayed on the page, and the database is not queried again. Therefore, the old data is displayed each time.

Solution:
There is a way of thinking. We can make it different in the URL of each request. We can add a parameter, and the value of this parameter is different each time, so it is better to get rid of the timestamp.
Copy codeThe Code is as follows:
Url: '{0}/portal/articleManager/getContents? Id = {1} & date = {2} '. format (window. baseUrl, $ ("# id"). val (), new Date ())

Here, id is a useful parameter, and date is not processed.

According to the information, the post request can avoid this problem. POST is considered to be a variable access (the browser believes that the submission of POST must be changed ).
There is also a simpler way to set:
Copy codeThe Code is as follows:
Cache: false,

The premise is that the requested cache does not exist.

Related Article

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.