Get cache in jquery

Source: Internet
Author: User

Get cache in jquery

There are many ways to solve this problem. The most direct is to replace the $. get () method with $. ajax (), and then configure cache: false. I don't like the tedious configuration method of $. ajax (). You can use the following simple method to implement it:

In the ie series, the $. get () method caches the returned results when the url address is fixed, leading to unexpected problems. But under Firefox, it will not be cached.

 

There are many ways to solve this problem. The most direct is to replace the $. get () method with $. ajax (), and then configure cache: false. I don't like the tedious configuration method of $. ajax (). You can use the following simple method:

 

At $. add new random parameters to get () data, such as {data: mydata, stamp: Math. random ()}, because each time the data is different, the data returned after the request is not cached.

 

You can also change $. get () to $. post () to solve this problem.

 

The permanent solution is to set global parameters, $. ajaxSetup ({cache: false}); after this setting, basically all get requests, jquery will automatically add the _ 1948838 additional parameter, which is generally similar to the preceding solution.

 

For example:

$. Get ("ProvinceListByCountryIDHandler. ashx ", {" cid ": $ drpCountry. val (), "time": new Date (). getTime ()}, function (data, returnStatus ){})

 

 

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.