BillyBoB Posted July 21, 2008 Share Posted July 21, 2008 I am creating a chat script for my upcoming game and when I send for the username/time/message it fills all three variables with object HTMLCollection.. Here's the code. javascript: var sendReq = getXmlHttpRequestObject(); var receiveReq = getXmlHttpRequestObject(); var lastMessage = 0; var mTimer; function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } } function getMessages(chatRoomId, divId) { obj = document.getElementById(divId); if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("GET", '../includes/getMessages.php?crid=' + chatRoomId + '&lm=' + lastMessage, true); receiveReq.onreadystatechange = function() { alert(receiveReq.readyState + " - " + receiveReq.status); if (receiveReq.readyState == 4 && receiveReq.status == 200) { var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); var n_messages = message_nodes.length for (i = 0; i < n_messages; i++) { var user_node = message_nodes[i].getElementsByTagName("user"); var text_node = message_nodes[i].getElementsByTagName("text"); var time_node = message_nodes[i].getElementsByTagName("time"); lastMessage = (message_nodes[i].getAttribute('id')); eDIV = document.createElement("div"); eDIV.setAttribute("class","FullMessage"); eAnchor = document.createElement("a"); eAnchor.setAttribute("href","#"); eAnchor.setAttribute("target","_blank"); eAnchor.appendChild(document.createTextNode(user_node)); eDIV.appendChild(eAnchor); eDIV.appendChild(document.createTextNode(" (" + time_node + "): " + text_node)); obj.appendChild(eDIV); /*<div class="FullMessage"><a href="#" target="_blank">alyis</a> (9:25 AM): Hi everyone this is my first message in the chat room.</div>*/ } mTimer = setTimeout('getMessages(' + chatRoomId + ',' + divId + ');',2000); } } receiveReq.send(null); } } HTML: <body onload="scrollBottom('ChatRoom'); getMessages('1','ChatRoom');"> Second HTML peice: <div id="ChatRoom"> </div> PHP: <?php require_once("functions.php"); require_once("objects.php"); $db = new Database("syck_polkamon"); $db->connectDB("syck","4<N#ly11TGn<"); //Send some headers to keep the user's browser from caching the response. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header("Cache-Control: no-cache, must-revalidate" ); header("Pragma: no-cache" ); header("Content-Type: application/xml; charset=utf-8"); //Create the XML response. $xml = '<?xml version="1.0" ?><root>'; if($_GET['lm']==0) { $sql = mysql_query("SELECT * FROM `chat_terminal` WHERE `chatid` = '$_GET[crid]' ORDER BY `timesent` DESC LIMIT 20"); while($info = mysql_fetch_array($sql)) { $xml .= '<message id="' . $info['id'] . '">'; $sql2 = mysql_query("SELECT * FROM `user_profiles` WHERE `id` = '$info[userid]'"); $info2 = mysql_fetch_array($sql2); $xml .= '<user>' . htmlspecialchars($info2['username']) . '</user>'; $xml .= '<text>' . htmlspecialchars($info['message']) . '</text>'; $time = getDBDate('g:i A', $info['timesent']); $xml .= '<time>' . $time . '</time>'; $xml .= '</message>'; } }else{ $sql = mysql_query("SELECT * FROM `chat_terminal` WHERE `chatid` = '$_GET[crid]' AND `id` > '$_GET[lm]' ORDER BY `timesent` DESC"); while($info = mysql_fetch_array($sql)) { $xml .= '<message id="' . $info['id'] . '">'; $sql2 = mysql_query("SELECT * FROM `user_profiles` WHERE `id` = '$info[userid]'"); $info2 = mysql_fetch_array($sql2); $xml .= '<user>' . htmlspecialchars($info2['username']) . '</user>'; $xml .= '<text>' . htmlspecialchars($info['message']) . '</text>'; $time = getDBDate('g:i A', $info['timesent']); $xml .= '<time>' . $time . '</time>'; $xml .= '</message>'; } } $xml .= '</root>'; echo $xml; ?> It displays: [object HTMLCollection] ([object HTMLCollection]): [object HTMLCollection] Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/115751-solved-output-error-object-htmlcollection/ Share on other sites More sharing options...
BillyBoB Posted July 21, 2008 Author Share Posted July 21, 2008 WOW I feel so stupid. but atleast I figured it out... I didn't call the value of the nodes... I am soo tired and dumb. Link to comment https://forums.phpfreaks.com/topic/115751-solved-output-error-object-htmlcollection/#findComment-595073 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.