Home > Web Front-end > JS Tutorial > Introduction to the simplest way to quickly solve the jquery get cache problem_jquery

Introduction to the simplest way to quickly solve the jquery get cache problem_jquery

WBOY
Release: 2016-05-16 17:08:20
Original
964 people have browsed it

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) {})

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template