BillyBoB Posted July 21, 2008 Share Posted July 21, 2008 I am creating a chat for my upcoming game and I am trying to build the users list. Javascript: function getUsers(divId, userId) { obj = document.getElementById(divId); if (userReq.readyState == 4 || userReq.readyState == 0) { userReq.open("GET", "../includes/getUsers.php?anticache=0", true); userReq.onreadystatechange = function() { alert(userReq.readyState + " - " + userReq.status); if (userReq.readyState == 4 && userReq.status == 200) { so_clearInnerHTML(obj); var xmldoc = userReq.responseXML; var user_nodes = xmldoc.getElementsByTagName("user"); var n_users = user_nodes.length for (i = 0; i < n_users; i++) { var id_node = user_nodes[i].getElementsByTagName("id"); var name_node = user_nodes[i].getElementsByTagName("name"); var perms_node = user_nodes[i].getElementsByTagName("perms"); eDIV = document.createElement('div'); if(perms_node[0].firstChild.nodeValue==1) { eIMG = document.createElement('img'); eIMG.setAttribute('src', '../images/icons/ModHammer.jpg'); eIMG.setAttribute('alt', 'Moderator'); eDiv.appendChild(eIMG); } if(id_node[0].firstChild.nodeValue==userId) { eDiv.appendChild(document.createTextNode(name_node[0].firstChild.nodeValue)); }else{ eAnchor = document.createElement('a'); eAnchor.onclick = function() { UserPopup(event) }; eAnchor.appendChild(document.createTextNode(name_node[0].firstChild.nodeValue)); eDiv.appendChild(eAnchor); } obj.appendChild(eDiv); } } } receiveReq.send(null); alert('hi'); } uTimer = setTimeout('getUsers(\'UserNames\',\''+userId+'\')', 2000); } 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>'; /*<user><id></id><name></name><perms></perms></user>*/ $i = 0; $sql = mysql_query("SELECT * FROM `chat_users`"); while($info = mysql_fetch_array($sql)) { $id[$i] = $info['id']; $i++; } $i = 0; foreach($id as $uid) { $sql = mysql_query("SELECT * FROM `user_profiles` WHERE `id` = '$uid'"); $info[$i] = mysql_fetch_array($sql); $i++; } $j = 0; $h = 0; foreach($info as $user) { $sql = mysql_query("SELECT * FROM `user_files` WHERE `id` = '$user[id]'"); $inf = mysql_fetch_array($sql); if($inf['perms']==1) { $mods[$j] = $user; $j++; }else{ $regs[$h] = $user; $h++; } } if($mods[0]) { foreach($mods as $mod) { $xml .= '<user>'; $xml .= '<id>' . $mod['id'] . '</id>'; $xml .= '<name>' . $mod['username'] . '</name>'; $xml .= '<perms>1</perms>'; $xml .= '</user>'; } } if($regs[0]) { foreach($regs as $reg) { $xml .= '<user>'; $xml .= '<id>' . $reg['id'] . '</id>'; $xml .= '<name>' . $reg['username'] . '</name>'; $xml .= '<perms>0</perms>'; $xml .= '</user>'; } } $xml .= '</root>'; echo $xml; ?> The php works fine http://syckgamingleague.com/includes/getUsers.php but for some reason the ajax isn't pulling that info.... as you can see I have it alert the status and readyState but these do not alert at all so it has to be around that line Thanks in advance Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 21, 2008 Author Share Posted July 21, 2008 I'm officially going to stop coding while I'm tired. I messed up on the send variable. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.