gpt4 book ai didi

javascript - 自动刷新 div 不起作用

转载 作者:行者123 更新时间:2023-12-03 10:24:36 25 4
gpt4 key购买 nike

我正在尝试开发一个 div,它会自动更新您自己的内容,因为它将在 Canvas 上显示真实的 ping 网站。
我有以下脚本:

<script> 
var auto_refresh = setInterval(
function()
{
$('#divcanvas').fadeOut('slow').load('teste.php #divcanvas').fadeIn("slow");
}, 1000);
</script>

在我的标记中有:

<div style="width:30%">
<div id="divcanvas">
<canvas id="canvas" height="450" width="600"></canvas>
</div>
</div>

在 test.php 中有:

<?php 
include_once "ping/pingdomain.php";
require_once "ping/config.php";
$ms = pingDomain('www.adhenrique.com.br');
$hora = date("H:i:s", time());
mysql_query("insert into ping (resposta, horario) values ('$ms', '$hora')");
$sql = mysql_query("SELECT * FROM PING order by id DESC LIMIT 0,15");
?>
<head>
<title>Documento sem título</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="includes/js/chart.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<canvas id="canvas" height="450" width="600"></canvas>
<?php
$pingreposta = array();
$pinghorario = array();
while($valor = mysql_fetch_assoc($sql))
{
extract($valor);
$pinghorario[] = $valor['horario'];
$pingreposta[] = $valor['resposta'];
}
?>
<script>
var lineChartData = {
labels :<?php echo '[' .'"'. implode('","', $pinghorario) .'"'. ']'; ?>
,
datasets : [
{
label: "My First dataset",
fillColor : "rgba(220,220,220,0.2)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : <?php echo '[' . implode(',', $pingreposta) . ']'; ?>

}
]

}

window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
});
}


</script>

</body>
</html>

但是当我打开index.php时,它不显示 Canvas 。但如果我打开 test.php 数据,它会显示。即canvas的代码是正确的。
我的错误在哪里?

最佳答案

在这一行,您犯了一个拼写错误:

$('#divcanvas').fadeOut('slow').load('teste.php #divcanvas').fadeIn("slow");

teste.php 我猜应该是test.php

关于javascript - 自动刷新 div 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29461433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com