<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chat Application - Retrieve messages</title>
<script language="javascript">
<!--
function pageLoaded() {
//setTimeout("getMessages()", 2000); //poll server again in one second
var content = document.getElementById("contents").innerHTML;
document.write("innerHTML:"+content);//this does not work
if (document.getElementById("contents").innerHTML != ""){
parent.loadMessages(document.getElementById("contents").innerHTML);
}
}
function getMessages(){
document.location.reload();
}
//-->
</script>
<link href="chat1.css" rel="stylesheet" type="text/css" />
</head>
<body onload="pageLoaded();">
<div id="contents" name = "contents" class="chatWindow">
<?php
/**
* [Retrieve all messages]
*
*
*/
$query = "select `UserName`, `Message` from `ChatMessages_tbl`, `ChatUsers_tbl`
where `ChatMessages_tbl`.`UserId` = `ChatUsers_tbl`.`Id`";
$stmt = $dbInstance->executeQuery($query);
$result = $stmt->result;
//echo $result;
if (is_resource($result)){
while($row = mysql_fetch_row($result)){
echo "<b>".$row[0]."</b>: ".$row[1]."<br />";
}
}
?>
</div>
</body>
</html>
It wont work because the server side script php loads first that should bring the content inside the div. only after that, the javascript should start to run, so the document.write will execute only after the contents are loaded into the div.
I dont really know wot AJAX is all about?
I got this idea elsewhere and I want to build this with OO features and according to my needs.
I always welcome your suggestions.
I was earlier thinking of using XMLHTTP but I couldnot get a response from a php file properly so I saved that for the next revision.
If any of you thinking of helping me with XMLHTTP, have a look at: viewtopic.php?t=36274&highlight=
raghavan20 wrote:I dont really know <span style='color:blue' title='ignorance is bliss'>what</span> AJAX is all about?
I got this idea elsewhere and I want to build this with OO features and according to my needs.
I always welcome your suggestions.
I was earlier thinking of using XMLHTTP but I couldnot get a response from a php file properly so I saved that for the next revision.
If any of you thinking of helping me with XMLHTTP, have a look at: viewtopic.php?t=36274&highlight=