开发者

How to refresh a div in which php code is executing

a group images are calling in a div and there we have given an option to rotate images if required.

Actually the image is rotating but it is not showing in the page( without doing 2 or 3 manual page refresh).

I have added

 <meta HTTP-EQUIV="Pragma" content="no-cache"/>
 <meta HTTP-EQUIV="Cache-Control" content="no-cache"/>

at head

also done

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)
开发者_如何学Python        window.location.replace(window.location+"?reloaded=true");
}
reloadOnceOnly(); //You can call this via the body tag if desired
</script>

<?php
}

But it is not showing the new rotated or changed image without another manual refresh.

Could you please help me on this?


Why not

<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>


If I understand you correctly, you're trying to use a PHP to code to refresh the webpage? However, the issue here is that once the PHP is output to the client, you can't have control over it already. The best thing to do in this context is to use JavaScript to do the refresh for you. Hope it helps :)


Hi Merlin, you might want to use a simpler logic like this:

<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>

Optionally you might want to pack it into a function for your use. Hope it helps (:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜