I'm playing around with ASP.net MVC and JQuery at the moment. I've come across behavour which doesn't seem to make sense.
I'm calling JQuery's $.getJSON
function to populate some div's. The event is triggered on the $(document).ready
event. This works perfectly.
There is a small AJAX.BeginForm
which adds another value to be used when populating the divs. It calls the remote function correctly and upon success calls the original javascript function to repopulate the divs.
Here is the weird part: In FireFox and Chrome - Everything works. BUT In IE8 (Beta) this second call to the populate Div script (which calls the $.getJSON function) gets cached data and does not ask the server!
Hope this question makes sense: In a nut shell - Why is $.getJSON
getting cached data? And why is it only effecting IE8?
This is how it worked for me...
$.ajaxSetup({ cache: false }); $.getJSON("/MyQueryUrl",function(data,item) { // do stuff with callback data $.ajaxSetup({ cache: true }); });
Just to let you know, Firefox and Chrome consider all Ajax request as non-cachable. IE (all versions) treat Ajax call just as other web request. That's why you see this behavior.
How to force IE to download data at each request:
Code:
public class NoCacheAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext context) { context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With