Ajax and Caching...

Discussion in 'JavaScript' started by NoamBarz, Jul 5, 2007.

  1. #1
    I'm using AJAX in a certain page.
    The function calls a php file that selects data from a certain table and writes the result into a div.
    My problem is that when I update the DB table and add items to it, the AJAX function doesn't display the new data. I have to clear my chache and then it displays everything properly. Is there a way to work around this problem?
     
    NoamBarz, Jul 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Ad a random dummy variable to the request URL.

    
    xml.open('GET', 'file.php?r=' + Math.floor(Math.random() * 1000));
    
    Code (javascript):
     
    nico_swd, Jul 5, 2007 IP