Question about cache of Ajax request results of IE

Source: Internet
Author: User

Source (detailed): http://www.cnblogs.com/artech/archive/2013/01/03/cache-4-ie.html

Solution 1: solve the problem by adding a suffix to the URL address

  <!  Doctype html  >   <  Html  >       <  Head  >                      <  Script  Type  = "Text/JavaScript"  > $ (  Function  () {Window. setinterval (  Function  () {$. Ajax ({URL:  '  @ URL. Action ("getcurrenttime ")?  '  +   New Date (). totimestring (), success:  Function  (Result) {$ (  "  Ul  "  ). Append (  "  <Li>  "   + Result  +   "  </LI>  "  );}});},  5000  );});  </  Script  >         </ Head  >    </  Html  > 

Solution 2: solve the problem through Ajax settings of jquery

 <!  Doctype html  >      <  Html  >          <  Head  >                      <  Script  Type = "Text/JavaScript"  >  $ (  Function  () {$. Ajaxsetup ({cache:  False  }); Window. setinterval (  Function  () {$. Ajax ({URL:  ' @ URL. Action ("getcurrenttime ")  '  , Success:  Function  (Result) {$ (  "  Ul  "  ). Append (  "  <Li> "   +  Result  +   "  </LI>  "  );}});},  5000  );});  </ Script  >         </  Head  >     </  Html  > 

Solution 3: Use MVC to solve problems through custom response

  Public   Class  Homecontroller: controller {  Public  Actionresult index (){  Return View ();} [nocache]  Public   String  Getcurrenttime (){  Return  Datetime. Now. tolongtimestring ();}}  Public   Class  Nocacheattribute: filterattribute, iactionfilter {  Public   Void Onactionexecuted (actionexecutedcontext filtercontext) {filtercontext. httpcontext. response. cache. setcacheability (httpcacheability. nocache );}  Public   Void  Onactionexecuting (actionexecutingcontext filtercontext ){}} 

 

 

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.