Ajax IE Cache related problem solving _ajax related

Source: Internet
Author: User
Using Ajax to do a name test, the first is effective, but submitted after the test again, the result is wrong, is due to the cache of IE reasons.
Copy Code code as follows:

function Verify () {
$.ajax ({
Issue for IE Cache; timestamp= "+ New Date (). GetTime ()
URL: "checkgroupname?timestamp=" + New Date (). GetTime (),
Async:true,
Data: "Groupname=" + $ ("#cn"). Val () + "&grouptypefordetail=" +$ ("#groupType"). Val () + "&prefix=" +$ ("#p"). Val () ,
DataType: "HTML",
Success:function (data) {
if (data==1) {
$ ("#result"). HTML ("<font color= ' green ' >group name[" +$ ("#p"). Val () + $ ("#cn"). Val () + "]valid</font>");
$ ("#email"). Val ($ ("#p"). Val () + $ ("#cn"). Val () +$ ("#emailHidden"). Val ());
$ (' #subData '). Removeattr ("Disabled");
}else if (data==2) {
$ ("#result"). HTML ("<font color= ' red ' >group name[" +$ ("#p"). Val () + $ ("#cn"). Val () +]already Existed.</font > ");
$ (' #subData '). attr (' disabled ', "true");
}else{
$ ("#result"). HTML ("<font color= ' Red ' >group name can not be empty.</font>");
$ (' #subData '). attr (' disabled ', "true");
}
}
});
}

principle
Firefox every request will return to the server to get the latest data, but IE is not the same, it will cache the previous data, only the first request will be true to the server to read data, resulting in AJAX data will not update over time ....
Solutions (collected from the Web)
1, in the service End plus header ("Cache-control:no-cache, must-revalidate"); Or better with the following combination:
Copy Code code as follows:

Header ("Expires:sat, 1 00:00:00 GMT");
Header ("last-modified:". Gmdate ("D, D M Y h:i:s"). " GMT ");
Header ("Cache-control:no-cache, must-revalidate");
Header ("Pragma:no-cache");

2, in the AJAX send the request before adding Xmlhttprequest.setrequestheader ("if-modified-since", "0");
3, in the AJAX send the request before adding Xmlhttprequest.setrequestheader ("Cache-control", "No-cache");
4, after the Ajax URL parameters plus "? fresh=" + math.random (); Of course, the parameter fresh can be arbitrarily taken.
5, the fourth method is similar to the third, after the URL parameter plus "? timestamp=" + New Date (). GetTime (); Recommend this way, I use this, personally think more convenient.
6. Replace get with post: not recommended
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.