php 显示图像 刷新,javascript-使用jquery刷新php并重新加载图像

我有这个php页面/var/www/oggi1ora.php.

首先,我需要执行/usr/local/bin/oggi1ora.php页面以生成图表.

每5秒钟php脚本会正确执行,但页面中的图像不会刷新…

我该如何解决?

我需要每5秒执行一次/usr/local/bin/oggi1ora.php.该脚本生成存储在/var/www/grafici/oggi1ora.png中的图像.

oggi1ora.png

function refresh_div() {

jQuery.ajax({

url:'oggi1ora.php',

type:'POST',

success:function(results) {

jQuery(".result").html(results);

}

});

}

t = setInterval(refresh_div,5000);

这是新的/var/www/oggi1ora.php

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");

header("Cache-Control: post-check=0, pre-check=0", false);

header("Pragma: no-cache");

include('/usr/local/bin/oggi1ora.php');

?>

oggi1ora.png

function refresh_div() {

var d = new Date().getTime();

jQuery.ajax({

url:'oggi1ora.php?ts=' + d,

type:'POST',

success:function(results) {

$("#oggi1ora").attr("src", "grafici/oggi1ora.png?ts=" + d);

}

});

}

t = setInterval(refresh_div,5000);

解决方法:

您可能有浏览器缓存问题.一种解决方案是在URL上附加时间戳,以确保获取最新版本.您可以将其设置为不缓存服务器端头.对于前一种解决方案,您可以尝试以下操作:

function refresh_div() {

var d = new Date().getTime();

jQuery.ajax({

url:'oggi1ora.php?ts=' + d,

type:'POST',

// rest of your code

对于后者,您可以这样设置标题:

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");

header("Cache-Control: post-check=0, pre-check=0", false);

header("Pragma: no-cache");

接下来,jQuery(“.result”).html(results)可能不做任何事情,因为在标记中没有带有“ result”类的元素.

相反,请忽略结果并强制刷新图像,如下所示:

function refresh_div() {

var d = new Date().getTime();

jQuery.ajax({

url:'oggi1ora.php?ts=' + d,

type:'POST',

success:function(results) {

$("#oggi1ora").attr("src", "grafici/oggi1ora.png?ts=" + d);

}

});

}

更新:如果您也想每5秒调用一次/usr/local/bin/oggi1ora.php,则可以添加’/usr/local/bin/oggi1ora.php'(或者设置目录结构)或添加exec(面向网络的/var/www/oggi1ora.php脚本中的“ php -q /usr/local/bin/oggi1ora.php”).

标签:javascript,php,jquery

来源: https://codeday.me/bug/20191120/2041482.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值