An introduction to the simplest way to quickly solve jquery's get caching problem

  • 2020-03-30 01:01:09
  • OfStack

Under the ie series, the $.get() method caches the results when the url is fixed, causing unexpected problems. Under firefox, it's not cached.

There are many ways to solve this problem, the most straightforward is to replace the $.get() method with $.ajax(), and then configure cache:false. I don't like the cumbersome configuration of $. Ajax (), which can be implemented in the simplest way:

Add a new random parameter after the data of $.get(), such as {data: mydata, stamp: math.random ()}. Since the data is different each time, the data returned after the request will not be cached.

You can also fix this problem by changing $.get() to $.post().

Once and for all, the solution is to set the global parameters, $.ajaxsetup ({cache:false}); With this setup, jquery automatically adds an additional parameter of _1948838 to almost all get requests, which in general is similar to the above solution.

Such as:
$.get (" ProvinceListByCountryIDHandler ashx, "{" cid" : $drpCountry. Val (), "time", new Date (). The getTime ()}, function (data, returnStatus) {})

Related articles: