NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

getElementsByTagName not finding desired tag

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    NetBeans Forums -> Ajax Users
View previous topic :: View next topic  
Author Message
helloise



Joined: 17 Feb 2011
Posts: 5
Location: sdfsd

PostPosted: Thu Aug 11, 2011 2:16 pm    Post subject: getElementsByTagName not finding desired tag Reply with quote

i have this part of code in JS:

Code:

     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:

Code:

$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
Back to top
paolosca



Joined: 09 Sep 2010
Posts: 384

PostPosted: Fri Aug 12, 2011 7:11 am    Post subject: Re: getElementsByTagName not finding desired tag Reply with quote

Hi Helloise,

On 08/11/2011 10:16 PM, helloise wrote:
Quote:
i get a "cannot cal a method getElementsByTagName of null" ???

It's hard to check without the whole code, did you set the right
Content-Type in the reply headers? Also the xml syntax doesn't look
correct to me, you should probably use <?xml version="1.0" ?> instead of
<?//xml version="1.0" ?>.


I.E.:

$xml = '<?xml version="1.0" ?>\n';
$xml .= '<root>\n';

// your code here

$xml .= '</root>\n';

header("Pragma: ");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Content-Type: text/xml");
header("Content-Disposition: attachment; filename=\"result.xml\"");

echo($xml);


Regards,


Paolo.
Back to top
helloise



Joined: 17 Feb 2011
Posts: 5
Location: sdfsd

PostPosted: Fri Aug 12, 2011 7:41 am    Post subject: Reply with quote

thank you wil take out the "//" and i changed
var xmldoc = receiveReq.responseText;

with

var xmldoc = receiveReq.responseXML;
and xmldoc now contain the right values
Back to top
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    NetBeans Forums -> Ajax Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo