Enjoy an ad free experience by logging in. Not a member yet?
Register .
01-26-2009, 09:36 AM
PM User |
#1
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
ajax is caching
my code is
Code:
<script>
$(document).ready(function()
{
var refreshId = setInterval(function()
{
$('#data').load('ajaxloadspread.asp'+ '?' + Math.random());
}, 1000);
});
</script>
this reloads the table every second - now the problem is it's not working on some versions of ie and I think it's because it is caching - can someone help me with how to fix.
I tried adding a random number at the end but that didn't make a difference.
01-26-2009, 03:05 PM
PM User |
#2
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
Well did you clear your cache after you made the changes to your JavaScript code? If the page is cached, it might not have picked up your new changes.
Better yet, make it use a post instead of a get, gets are cached, posts are not:
Code:
$("#data").load("ajaxloadspread.asp", { 'foo': 'bar' } );
Eric
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
01-26-2009, 03:09 PM
PM User |
#3
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
How do I do that?
does your line of code make it a get?
sorry i'm new to ajax and this is my first application i'm writing in ajax so I would appreciate your help .
01-26-2009, 03:15 PM
PM User |
#4
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
If you read the documentation it says if you add extra parameters to the load, it uses a post instead of a get. YOUR code is a GET, the example I posted is a POST.
HTTP guideliens do not allow for posts to be cahced, only gets can be. You want GETs to be cached so when you are surfing the net, everything runs faster.
If you still want to use a GET request, than you need to set the correct No Cahce headers in your serverside code.
Eric
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
01-26-2009, 03:22 PM
PM User |
#5
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
so i changed my line of code to
$("#data").load("ajaxloadspread.asp", { 'foo': 'bar' } );
same thing - it's not working on ie - what else could be the problem?
01-26-2009, 03:33 PM
PM User |
#6
Senior Coder
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
Did you clear your browsers cache to make sure you have the latest and greatest JavaScript code available?
Eric
__________________
Tech Author [Ajax In Action, JavaScript : Visual Blueprint]
01-26-2009, 03:42 PM
PM User |
#7
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
yes I cleared cache and it is still not refreshing
01-26-2009, 04:59 PM
PM User |
#8
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
If you still want to use a GET request, than you need to set the correct No Cahce headers in your serverside code.
How would I do this
01-27-2009, 06:24 AM
PM User |
#9
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
http MUST honor a client explicitly requesting a new version:
setting a request header ("If-Modified-Since") can prevent cache without server config:
Code:
XHR.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
jQuery provides it's own, simple way :
Code:
var refreshId = setInterval(function()
{
$.ajax({
url: 'ajaxloadspread.asp',
cache: false,
success: function(html){
$("#data").replaceWith(html);
}
});
}, 3000);
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
01-27-2009, 07:21 AM
PM User |
#10
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
that is still not working?
what else coudl be the issue that would be disabling ajax?
01-27-2009, 07:23 AM
PM User |
#11
Senior Coder
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
your change above stopped it from working on firefox also ?
01-27-2009, 08:54 AM
PM User |
#12
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
Quote:
Originally Posted by
esthera
your change above stopped it from working on firefox also ?
i posted the ready function body, i guess i should have made that more clear ;^)
cut and paste ready:
Code:
<script>
$(document).ready(function(){
var refreshId = setInterval(function(){
$.ajax({
url: 'ajaxloadspread.asp',
cache: false,
success: function(html){
$("#data").replaceWith(html);
}
});
}, 3000);
});
</script>
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 08:15 PM .
Advertisement
Log in to turn off these ads.