肖恩D++
Not Equal C && !=C && 不等于西
-
jQuery $.ajax()/$.get() function always get same value for IE
Posted on June 19th, 2014 Add commentsWhen I was trying to use jQuery $.ajax() or $.get() function retrieve some random value from the server side, it’s working fine on firefox or chrome, but not IE. The server side code like below (written in ASP.NET MVC):
1234567public class HomeController : Controller{public ActionResult GetRandomCount(){return Json(new Random().Next(1, 100), JsonRequestBehavior.AllowGet);}}The client side code:
12345678<a href="javascript:void(0)" onclick="CheckCount()">Check Count</a><script>function CheckCount(){$.get('/Home/GetRandomCount', function (data) {alert(data);});}</script>I’m supposed to get a random number every time I click the link, but in IE, always same one returned. Regarding Craic Computing’s Blog, that’s because IE will cache the value first returned, and trade rest requests as identical by default, so it won’t update the value since the request URL never change.
To fix this issue, just disable cache in the jQuery function as following:12345678function CheckCount(){$.ajaxSetup ({cache: false});$.get('/Home/GetRandomCount', function (data) {alert(data);});}
16 views
Recent Comments