简体   繁体   English

Javascript / PHP中的缓慢刷新

[英]Slow refresh in Javascript/PHP

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. 我有一个网站,该网站通过一段javascript和php代码获取一个文件夹,随机选择一个图像,然后在页面的div标签中显示它。 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. 单击刷新按钮后,它会立即显示图像,但是如果再次按下它,则不会立即显示新图像,除非大约10秒钟后按下。 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. 我已经尝试了一些事情,例如使用html meta标记来清除缓存/不存储它以便始终刷新,但是它没有用。 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. 我还尝试了用其他方法在stackoverflow.com上找到的许多不同的javascript代码,但是似乎只有在10秒钟左右按下后它们才会刷新。

Considering there's quite a lot of code. 考虑到有很多代码。 I've put the code into a pastebin for simplicity. 为了简单起见,我将代码放入了一个pastebin中。

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. 请注意,PHP代码是从WWW借来的,并且我对其进行了非常小的更改,除了添加了最后一行代码外,没有其他更改。

http://pastebin.com/wwys5r3E http://pastebin.com/wwys5r3E

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());
            }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM