...

View Full Version : ajax is caching



esthera
01-26-2009, 10:36 AM
my code is

<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.

A1ien51
01-26-2009, 04:05 PM
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. :D

Better yet, make it use a post instead of a get, gets are cached, posts are not:

$("#data").load("ajaxloadspread.asp", { 'foo': 'bar' } );

Eric

esthera
01-26-2009, 04:09 PM
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 .

A1ien51
01-26-2009, 04:15 PM
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

esthera
01-26-2009, 04:22 PM
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?

A1ien51
01-26-2009, 04:33 PM
Did you clear your browsers cache to make sure you have the latest and greatest JavaScript code available?

Eric

esthera
01-26-2009, 04:42 PM
yes I cleared cache and it is still not refreshing

esthera
01-26-2009, 05:59 PM
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

rnd me
01-27-2009, 07:24 AM
http MUST honor a client explicitly requesting a new version:

setting a request header ("If-Modified-Since") can prevent cache without server config:


XHR.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");





jQuery provides it's own, simple way :


var refreshId = setInterval(function()
{

$.ajax({
url: 'ajaxloadspread.asp',
cache: false,
success: function(html){
$("#data").replaceWith(html);
}
});


}, 3000);

esthera
01-27-2009, 08:21 AM
that is still not working?
what else coudl be the issue that would be disabling ajax?

esthera
01-27-2009, 08:23 AM
your change above stopped it from working on firefox also ?

rnd me
01-27-2009, 09:54 AM
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:



<script>

$(document).ready(function(){
var refreshId = setInterval(function(){

$.ajax({
url: 'ajaxloadspread.asp',
cache: false,
success: function(html){
$("#data").replaceWith(html);
}
});

}, 3000);
});
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum