Jump to content

Recommended Posts

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

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?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.