September 18, 2012
Failed to reload content via Ajax
Question by Dr.Kameleon
OK, so basically this is my issue :
- I’ve got a dynamic page with a table in it
- When the user clicks to delete an entry, the entry is deleted from the db and the table is reloaded (via a controller) using Ajax
- However, even when the content is re-fetched, it keeps showing the PREVIOUS version of my contents (as if the page was somehow cached?). If I reload the whole page, it shows up alright…
What could be going on?
Answer by Bardo
Are you using Chrome?
I’ve found similar behaviours when using ajax calls on Chrome.
If you are using jQuery to do the ajax call you can use the attribute cache: false for the method ajax to avoid this behaviour.
Answer by Starx
Its actually a caching related problem. So, to ensure this, just emulate fresh URI like
$.post("yourupdatepage.php?r="+(Math.random() * (1000 - 1) + 1),
...
);