Home >Web Front-end >JS Tutorial >Introduction to the simplest way to quickly solve the jquery get cache problem_jquery
In the IE series, when the URL address is fixed, the $.get() method will cache the returned result, causing unpredictable problems. But under Firefox, it will not be cached.
There are many ways to solve this problem. The most direct one is to replace the $.get() method with $.ajax(), and then configure cache: false. I don’t like the cumbersome configuration method of $.ajax(). You can implement it in the following simplest way:
Add new random parameters 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 change $.get() to $.post() to solve this problem.
The once and for all solution is to set global parameters, $.ajaxSetup({cache:false}); after setting this, basically all get requests jquery will automatically add additional parameters with the word _1948838, generally speaking, it is the same as the above The solution is similar.
For example:
$.get("ProvinceListByCountryIDHandler.ashx", { "cid": $drpCountry.val(), "time": new Date() .getTime() }, function(data, returnStatus) {})