Javascript PHP表是';t显示
我有一个Javascript PHP表是';t显示,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个PHP脚本,它连接到一个MySQL数据库,应该以HTML格式输出一个表。我已经厌倦了设置一个长轮询AJAX脚本来每秒轮询我的PHP脚本。它似乎是根据我在浏览器调试器中看到的内容工作的,但是该表没有显示在页面上。有人能帮我找到我的代码有什么问题吗 reocrd.php <?php header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00
PHP
脚本,它连接到一个MySQL
数据库,应该以HTML格式输出一个表。我已经厌倦了设置一个长轮询AJAX脚本来每秒轮询我的PHP
脚本。它似乎是根据我在浏览器调试器中看到的内容工作的,但是该表没有显示在页面上。有人能帮我找到我的代码有什么问题吗
reocrd.php
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
flush();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$servername = "localhost";
$username = "recorduser";
$password = "recorduser";
$database = "record";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * from username ORDER BY id DESC LIMIT 1";
$result = mysqli_query($conn, $sql);
echo "
<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "</tr>";
echo "</table>";
}
mysqli_close($conn);
?>
</body>
</html>
假设您有一个
,也许这可以工作?请尝试设置值属性,而不是设置值属性
因为您试图将HTML块添加到语言
value
属性?还有salesguage
吗?为什么会有这么多人?请尝试success:function(data){$('body')。append(data).
。这将防御性地测试PHP脚本是否返回某些内容。HTML代码中有一些奇怪的内容。为什么要在body
标记内重复
标记?还有,为什么要放置echo“”在while循环中?你正在关闭表的每一行。@davidkonrad你证明我的代码不起作用。你所说的salesguage
是什么意思?我在index.html
中用
厌倦了你的代码,但不起作用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Comet php backend</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery- 1.11.2.min.js"></script>
<script type="text/javascript" src="client1.js"></script>
</head>
<h1>Response from server:</h1>
</body>
</html>
setInterval(function(){
$.ajax({
url : "record.php",
success : function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
},
dataType : "json"
});
}, 30000);
setInterval(function(){
$.ajax({ url: "record.php", success: function(data){
//Update your dashboard gauge
$("#salesGuage").html(data.value);
}, dataType: "json"});
}, 30000);@