helloise Posted August 11, 2011 Share Posted August 11, 2011 i have this part of code in JS: var receiveReq = getXmlHttpRequestObject(); function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } } function getChatText() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("GET","getChat_xml.php?chat=1&last=7", true); receiveReq.onreadystatechange = handleReceiveChat; receiveReq.send(); } } function handleReceiveChat() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); } } then in my getChat_xml.php i have: $xml = '<?//xml version="1.0" ?><root>'; $last = 7; $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time" . " FROM message WHERE chat_id = " . db_input($_GET['chat']) . " AND message_id = " . $last; $message_query = db_query($sql); while($message_array = db_fetch_array($message_query)) { $xml .= '<message id="' . $message_array['message_id'] . '">'; $xml .= '<user>' . htmlspecialchars($message_array['user_name']) . '</user>'; $xml .= '<text>' . htmlspecialchars($message_array['message']) . '</text>'; $xml .= '<time>' . $message_array['post_time'] . '</time>'; $xml .= '</message>'; } $xml .= '</root>'; echo $xml; i get a "cannot cal a method getElementsByTagName of null" ??? i have no idea whats going on, help please? thanks Quote Link to comment https://forums.phpfreaks.com/topic/244503-getelementsbytagname-not-finding-desired-tag/ Share on other sites More sharing options...
AyKay47 Posted August 11, 2011 Share Posted August 11, 2011 i would start by alerting the contents of "receiveReq.responseXML" to confirm the correct results. function handleReceiveChat() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; alert(xmldoc); var message_nodes = xmldoc.getElementsByTagName("message"); }} my hunch here is that you will want responseText and not responseXML, is your php page content type text/plain or text/xml? Quote Link to comment https://forums.phpfreaks.com/topic/244503-getelementsbytagname-not-finding-desired-tag/#findComment-1255866 Share on other sites More sharing options...
helloise Posted August 11, 2011 Author Share Posted August 11, 2011 in my getChat_xml.php: header("Content-Type: text/xml; charset=utf-8"); i did do alert(xmldoc) and it returns null i changed the responsXML to responsText and now have values for xmldoc: <?//xml version="1.0" ?><root><message id="7"><user>Me, ME, me and mE </user><text>dfhdfgdfg</text><time>11:04</time></message></root> dfgdfg yipeee now to get the values.. thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/244503-getelementsbytagname-not-finding-desired-tag/#findComment-1255883 Share on other sites More sharing options...
AyKay47 Posted August 11, 2011 Share Posted August 11, 2011 no problem, any more trouble with this let us know Quote Link to comment https://forums.phpfreaks.com/topic/244503-getelementsbytagname-not-finding-desired-tag/#findComment-1255888 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.