Reputation: 127
i am making a simple project..and i need to load data from other page in an
index.php..and i have set time of 20sec. but its not working.. could u please
tell me what is wrong with the query..Thanks already..
<?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>";
}
?>
Upvotes: 0
Views: 978
Reputation: 1265
You have to add jquery js in your html code. you can use online 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>
Upvotes: 3