Ajax automatically clears cache or does not cache practices

Source: Internet
Author: User

Ajax automatically clears cache or does not cache practices

Foreground HTML submission with JS script under Operation

Method One:

Add timestamp to Submission

That is modified at PostURL to:

var posturl= "/ashx/vote.ashx?id=" +obj+ "&optionid=" +sellist+ "&guid=" +new date (). gettime ();

+ "&guid=" +new date (). gettime ();

Plus this time, the problem is solved. Obviously Ajax returns the backend processing results in real time, which we aim to achieve. Ok
Method Two:

Using the Get URL with a random parameter can realize the Ajax automatic cache refresh.


Simple implementation Code

function Verify () {
Get the values in the page text box by using jquery
var url = "Ajaxserver?name=" + encodeURI (encodeURI ($ ("#username"). Val ());
Special handling of incoming values through Converturl, so that each data has a timestamp, resulting in a different xhttprequest request
url = converturl (URL);
Call the GET request method in jquery to pass the value to the server and define a callback function to display the data returned on the server side of the page
$.get (url,null,function (data) {
$ ("#result"). HTML (data);
});
}
Add timestamp to URL address, cheat browser, do not read cache
function Converturl (URL) {
Get time stamp
var timstamp = (new Date ()). valueof ();
To stitch timestamp information to a URL
url = "Ajaxserver"
if (Url.indexof ("?") >= 0) {
url = url + "&t=" + timstamp;
} else {
url = url + "? t=" + Timstamp;
}
return URL;
}

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.