Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-26-2009, 09:36 AM   PM User | #1
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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.
esthera is offline   Reply With Quote
Old 01-26-2009, 03:05 PM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Old 01-26-2009, 03:09 PM   PM User | #3
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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 .
esthera is offline   Reply With Quote
Old 01-26-2009, 03:15 PM   PM User | #4
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Old 01-26-2009, 03:22 PM   PM User | #5
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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?
esthera is offline   Reply With Quote
Old 01-26-2009, 03:33 PM   PM User | #6
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Old 01-26-2009, 03:42 PM   PM User | #7
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
yes I cleared cache and it is still not refreshing
esthera is offline   Reply With Quote
Old 01-26-2009, 04:59 PM   PM User | #8
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
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
esthera is offline   Reply With Quote
Old 01-27-2009, 06:24 AM   PM User | #9
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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%
rnd me is offline   Reply With Quote
Old 01-27-2009, 07:21 AM   PM User | #10
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
that is still not working?
what else coudl be the issue that would be disabling ajax?
esthera is offline   Reply With Quote
Old 01-27-2009, 07:23 AM   PM User | #11
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,430
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
your change above stopped it from working on firefox also ?
esthera is offline   Reply With Quote
Old 01-27-2009, 08:54 AM   PM User | #12
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by esthera View Post
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%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 PM.


Advertisement
Log in to turn off these ads.