Home > Web Front-end > JS Tutorial > body text

How to deal with the caching problem of jquery.getJSON under IE_jquery

WBOY
Release: 2016-05-16 17:39:01
Original
953 people have browsed it


I encountered a problem in the project. Under Firefox, $.getJSON(); requested data and everything was normal, but under IE, $.getJSON(); only requested data once, and the second time it failed at all. The request is no longer sent. I found out after using fiddler to capture it. The request was not sent the second time and it was normal after I changed it to post

$.getJSON() has a caching problem. If the url it calls has been called before, the callback function will directly obtain the desired value in the cache instead of entering the background

The solution is as follows:

1. Make the URL different each time it is called.

Method: Add a random number to the parameter

Copy code The code is as follows:

$.getJSON("/Member/GetExercise.html" , { id: $("#Wareid").val(), isBool: loop, random:
Math.random() }, function (data) });

Copy code The code is as follows:

$.getJSON("/Member/GetExercise.html?random=Math.random ", { id: $("#Wareid").val(),
isBool: loop,}, function (data) });

Using new Date() can also be regarded as a random URL

Copy code The code is as follows:

?random=new Date().getTime()

2. Set cache to false

Copy code The code is as follows:

$.ajax({
type:"GET ",
url:'/Member/GetExercise.html',
cache:false,
dataType:"json",
success:function (data){
alert(data);
}
});
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