如何刷新执行php代码的div
一组图像正在调用一个div,在那里我们提供了一个选项,可以根据需要旋转图像 实际上,图像正在旋转,但如果不执行2或3次手动页面刷新,图像不会显示在页面中 我补充说如何刷新执行php代码的div,php,javascript,ajax,refresh,page-refresh,Php,Javascript,Ajax,Refresh,Page Refresh,一组图像正在调用一个div,在那里我们提供了一个选项,可以根据需要旋转图像 实际上,图像正在旋转,但如果不执行2或3次手动页面刷新,图像不会显示在页面中 我补充说 <meta HTTP-EQUIV="Pragma" content="no-cache"/> <meta HTTP-EQUIV="Cache-Control" content="no-cache"/> 头部 也做了 if(isset($_GET['re'])=='re') { ?> <scr
<meta HTTP-EQUIV="Pragma" content="no-cache"/>
<meta HTTP-EQUIV="Cache-Control" content="no-cache"/>
头部
也做了
if(isset($_GET['re'])=='re')
{
?>
<script language="JavaScript" type="text/javascript">
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;
function reloadOnceOnly() {
if (!reloaded)
window.location.replace(window.location+"?reloaded=true");
}
reloadOnceOnly(); //You can call this via the body tag if desired
</script>
<?php
}
但如果没有另一次手动刷新,它不会显示新的旋转或更改的图像
你能帮我一下吗?如果我没听错,你是想用PHP代码刷新网页?然而,这里的问题是,一旦PHP输出到客户端,您就无法控制它了。在这种情况下,最好使用JavaScript为您进行刷新。希望有帮助: 嗨,Merlin,您可能想使用一种更简单的逻辑,如下所示:
<script type="text/javascript">
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=");
if (loc == -1){
window.location.replace(window.location+"?reloaded=true");
}
</script>
或者,您可能希望将其打包到函数中以供使用。希望有帮助:为什么不
<script>
function rotate(imgId,direction) {
var img = document.getElementById(imgId);
img.src=img.src.split("rotation=")[0]+"rotation="+direction+"&rnd="+new Date().getTime();
return false;
}
</script>
<img id="image1" src="getimage.php?name=image1&rotation=0" /><br />
<a href="#" onclick="return rotate('image1',0)">Reset</a>
<a href="#" onclick="return rotate('image1',1)">90°</a>
<a href="#" onclick="return rotate('image1',2)">180°</a>
<a href="#" onclick="return rotate('image1',3)">270°</a>
现在我使用了一个代码来刷新页面。但是它不会一直显示更改后的图像。我想添加一个代码来刷新div而不刷新整个页面对于您关于刷新div而不刷新整个页面的观点,最好使用带有setInterval或setTimeout函数的JavaScript。关于刷新未显示的第一点,您是否检查过它是否未缓存在浏览器中?merlin,我认为您希望使用ajax。@merlin对迟来的答复表示歉意。请看我的答案后的水平页行。希望有帮助:出于向前兼容性的原因,您可能希望将ifisset$\u GET['re']=='re'更改为ifisset$\u GET['re']。很奇怪,你把一个已知的bool和一个已知的字符串进行比较,==。。。编辑或如果您实际上正在尝试检查其值:IFAsset$\u GET['re']&&$\u GET['re']='re'