NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
helloise
Joined: 17 Feb 2011 Posts: 5 Location: sdfsd
|
Posted: Thu Aug 11, 2011 2:16 pm Post subject: getElementsByTagName not finding desired tag |
|
|
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
|
Posted: Fri Aug 12, 2011 7:11 am Post subject: Re: getElementsByTagName not finding desired tag |
|
|
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
|
Posted: Fri Aug 12, 2011 7:41 am Post subject: |
|
|
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 |
|
 |
|
|
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
|
|