I have a site that through a piece of javascript and php code takes a folder, randomly picks an image and then shows it in a div tag on the page. Whilst all this works properly, showing the image in the right size and all. There is still a minor issue, it is pretty slow. Upon clicking the refresh button, it instantly shows an image, though if pressed again it won't instantly show a new image unless pressed after 10 or so seconds. Whilst this of course, is a minor issue, it is pretty annoying. I've tried a few things such as using html meta tags to clear the cache/not store it in order to always refresh, but it didn't work. I've also tried numerous of different javascript code that I found on stackoverflow.com of other ways to do it, but they all seemed to only refresh if pressed after 10 or so seconds.
Considering there's quite a lot of code. I've put the code into a pastebin for simplicity.
Note that the PHP code is borrowed from the WWW, and I have done very minor changes to it, less than none except adding the last line of code.
Hope we can find a solution together, thanks!
Try this, the requests are defiantly getting cached server side.
function reloadImg(){
if(document.refreshform.randomhero[1].checked == true) {
$("#randomhero").load("random-herosup.php?u="+new Date().getTime());
}
else if(document.refreshform.randomhero[2].checked == true) {
$("#randomhero").load("random-herocar.php?u="+new Date().getTime());
}
else if(document.refreshform.randomhero[3].checked == true) {
$("#randomhero").load("random-heromid.php?u="+new Date().getTime());
}
else
{
$("#randomhero").load("random-heroall.php?u="+new Date().getTime());
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.