How to solve the cache problem of jquery. getJSON in ie

Source: Internet
Author: User


A problem occurs in the project. Under Firefox, $. getJSON (); The request data is normal, but in IE, $. getJSON (); only requests data once. The second request is not sent at all. It is known that it was captured by fiddler. If the second request is not sent, it will be normal if it is changed to post.

$. GetJSON () has a cache problem. If the called url 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 URLs of each call different.

Method: Add a random number to the parameter.

Copy codeThe Code is as follows:
$. GetJSON ("/Member/GetExercise.html", {id: $ ("# Wareid"). val (), isBool: loop, random:
Math. random ()}, function (data )});

Copy codeThe Code is as follows:
$. GetJSON ("/Member/GetExercise.html? Random = Math. random ", {id: $ (" # Wareid "). val (),
IsBool: loop,}, function (data )});

Using new Date () is also a random URL.
Copy codeThe Code is as follows:
? Random = new Date (). getTime ()

2. Set the cache to false.

Copy codeThe Code is as follows:
$. Ajax ({
Type: "GET ",
Url: '/Member/GetExercise.html ',
Cache: false,
DataType: "json ",
Success: function (data ){
Alert (data );
}
});

Related Article

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.