Ok i'm trying to build a forum with jquery ajax characteristics. Below is the html/jquery coding. And i know jquery is loaded because I did the alert(1); inside the document ready and it worked.

<!doctype>
<html>
<head>
	<title>Shouts!</title>
	<script src="jquery.js"></script>
	<script>
	$(document).ready(function() {
		$("#messages").load(function('loadchat.php');
		
		$("#post").submit(function(){
		
			return false;
		});
	});
		
	</script>
</head>
<body>
<div id="messages"></div>
<table width="480" BACKGROUND="images/commentback.jpg">
     <tr>
         <td>             
             <form id="post" method="post" action="datetest.php">
              <span class="whitetitle">Name:<br><input name="messages" type="text" STYLE="background: white; border: 1px #000000 solid;"><br >
              <input type="submit" value="send">
              </form>
         </td>
     </tr>
</table>
</div>
<br><br>
</body>
</html>

Below is the php load I'm using to load my database info. I've ran this without jquery and it works fine but I want it to load in messages id. Do I have to so something different when i integrate php and jquery that I'm not aware of?

<?php

include 'config2.php';
$dbname = 'test';
$tablename = 'time';
include 'opendb.php';

$res = mysql_query("SELECT timestamp, message FROM time ORDER BY timestamp DESC LIMIT 0,10;");

while ( $row = mysql_fetch_array($res) ) {
	echo $row["message"] . "<br />";
	echo $row["timestamp"] . "<br />";
	echo date("g:i a F j, Y ",  $row["timestamp"] ) . "<br /><br />";
}
?>
Member Avatar for cuonic

Do you receive an error when you load up the page or does it still display ?

I think the problem might just be the jQuery. I don't really understand what you're trying to do with .load(function('loadchat.php')). Try the following :

<!doctype>
<html>
<head>
<title>Shouts!</title>
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
$("#messages").load('loadchat.php');
 
$("#post").submit(function(){
 
return false;
});
});
 
</script>
</head>
<body>
<div id="messages"></div>
<table width="480" BACKGROUND="images/commentback.jpg">
<tr>
<td>
<form id="post" method="post" action="datetest.php">
<span class="whitetitle">Name:<br><input name="messages" type="text" STYLE="background: white; border: 1px #000000 solid;"><br >
<input type="submit" value="send">
</form>
</td>
</tr>
</table>
</div>
<br><br>
</body>
</html>

I'm trying to load the data that I have in my database (test1, test2) in the div messages. loadchat.php works alone without jquery

localhost/loadchat.php

but doesn't work when i'm loading it to jquery.

$("#messages").load(function('loadchat.php'); should be $("#messages").load(function('loadchat.php'));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.