Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: ajax is caching

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    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.

  • #2
    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
    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]

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    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 .

  • #4
    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
    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]

  • #5
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    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?

  • #6
    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
    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]

  • #7
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts
    yes I cleared cache and it is still not refreshing

  • #8
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    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

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,372
    Thanks
    11
    Thanked 591 Times in 572 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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #10
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts
    that is still not working?
    what else coudl be the issue that would be disabling ajax?

  • #11
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts
    your change above stopped it from working on firefox also ?

  • #12
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,372
    Thanks
    11
    Thanked 591 Times in 572 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •