Help: AJAX, IE7 and Cache

Discussion in 'JavaScript' started by sanjayc, Nov 15, 2006.

  1. #1
    Hello everybody,
    I have written a webpage with some AJAX updates.

    What happens
    1. DB updated
    2. Every 10 seconds browser checks server for new information
    3. In firefox new info is sent to the browser and end of story.

    HOWEVER
    3. In IE7 the page does not refresh, I know this is because the GET url (post.php) is stored locally in IE's cache. If I delete all internet cache the page updates. But this is not really a suitable for my users/friends.

    What I'm asking is if there is anyway I can make post.php not be cached by IE?

    I have tried putting the following code in my post.php
    <head>
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    </head>

    ... but that didn't work. I'm kinda of struggling. Any help would be hugely appreciated.

    Thanks
     
    sanjayc, Nov 15, 2006 IP
  2. sanjayc

    sanjayc Guest

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just to let you know I have found the solution and it was pretty simple too.
    Change all

    xmlHttp.open("GET",url,true)
    to
    xmlHttp.open("POST",url,true)

    Seems to have fixed it for me. Hope it helps you all if you happen to have the same problem.

    Cheers
    Sanjay
     
    sanjayc, Nov 15, 2006 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    You can also add a random number to the GET url, like that.

    
    var url = 'http://url.com/file.php?r='+ Math.floor(Math.random()*1000);
    
    Code (javascript):
     
    nico_swd, Nov 15, 2006 IP