我正在制作一个简单的项目......我需要从其他页面加载数据 index.php ..我已经设定了20秒的时间。但它不起作用..请你 告诉我查询有什么问题。谢谢..
<?php
include 'connection.php';
?>
<html>
<head>
<title>
My First Chat app
</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
$(document).ready(function(e) {
$.ajaxSetup({cache:false});
setInterval(function(){$('#logs').load('logs.php'); } ,2000);
});
</script>
</head>
<body>
<center><h1>Chat Box in PHP!!</h1><br><br><br></center>
<form name="form1">
<center>
<strong>Username:</strong><input type="text" name="uname"
style="width:200px;"><br><br>
<strong> Message:</strong> <textarea name="msg"
style="width:201px;"></textarea>
<br>
<a href="#" onClick="sheikh()">Send</a><br><br><br><br>
</center>
<div id="logs">
<br> <img src="icon.png">Loading chatlogs please wait...
</div>
</form>
</body>
</html>
<?php
$con=mysqli_connect("localhost","root","","chat");
$sqli="SELECT * FROM `logs` ORDER BY `id` DESC";
$result=mysqli_query($con,$sqli);
while($res=mysqli_fetch_assoc($result)){
echo "<span class='uname'>" .$res["username"]."</span>:<span
class='msg'>" .$res["message"]. "</span><br>";
}
?>
答案 0 :(得分:3)
你必须在你的html代码中添加jquery js。你可以使用在线jquery。
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>