如何刷新正在执行php代码的div

发布于 2024-11-04 13:04:37 字数 928 浏览 5 评论 0原文

一组图像在 div 中调用,我们提供了一个在需要时旋转图像的选项。

实际上图像正在旋转,但它没有显示在页面中(没有进行 2 或 3 次手动页面刷新)。

添加

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

但如果没有再次手动刷新,它不会显示新的旋转或更改的图像。

你能帮我解决这个问题吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠栀 2024-11-11 13:04:37

为什么不呢

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

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>
拧巴小姐 2024-11-11 13:04:37

如果我理解正确的话,您是在尝试使用 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>

或者您可能想要将其打包到一个函数中以供您使用。希望它有帮助(:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文