Hunter
April 7th, 2010, 12:00 PM
Main problem:
For some reason a function which I haveFor some reason the first function is stopping my second function from working when I click a button which has an onclick even of getMessage().
I know this because I put some alerts into the getMessage() function and they would not excectue until I deleted the first function.
<script type="text/javascript">
function getXmlHttpRequestObject() {
alert("Get XmlHttpObject!");
if (window.XMLHttpRequest)
{
// code for decent browsers such as IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for crap like IE6, IE5
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
else {
document.getElementById('p_status').innerHTML =
"Status: Could not create XmlHttpRequest Object, please upgrade your browser!";
}
//Make variables for later use
var lastMess = 0;
var sendReq = getXmlHttpRequestObject();
var receiveReq = getXmlHttpRequestObject();
var mTimer;
function getMessage() {
alert("Get XmlHttpObject!");
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
alert("Get XmlHttpObject!");
//var url = "scripts/get_data.php?uid=<?=$_SESSION['uid']?>&m=" + lastMess + "&chat=1";
var url = "testXMLdoc.xml";
receiveReq.open("GET", url, true);
receiveReq.onreadystatechange = manageMessage;
receiveReq.send(null);
lastMess++;
}
}
function manageMessage() {
if (receiveReq.readyState == 4) {
var xmldoc = receiveReq.responseXML;
var chat_div = document.getElementById('chat');
var msg_nodes = xmldoc.getElementByTagName("message");
var n_msg = message_nodes.length;
for (i = 0; i < n_msg; i++) {
var sender_node = msg_node[i].getElementByTagName["sender"];
var receiver_node = msg_node[i].getElementByTagName["receiver"];
var time_node = msg_node[i].getElementByTagName["time"];
var text_node = msg_node[i].getElementByTagName["text"];
chat_div.innerHTML = "Here: <br />" + sender_node[0].firstChild.nodeValue + "<br />";
chat_div.innerHTML = reciever_node[0].firstChild.nodeValue + "<br />";
chat_div.innerHTML =time_node[0].firstChild.nodeValue + "<br />";
chat_div.innerHTML = text_node[0].firstChild.nodeValue + "<br />";
}
}
}
</script>
Edit: manageMessage() function doesn't work and I understand why lol.
Problem which is probably causing the main problem:
The alert at the top of this function will not show...
function getXmlHttpRequestObject() {
alert("HTTP XML REQUEST!");
var httpxml;
if (window.XMLHttpRequest)
{
// code decent browsers like Firefox, Chrome, Opera, Safari. And IE7+...
httpxml = new XMLHttpRequest();
return httpxml;
}
else {
if (window.ActiveXObject) {
//Code for crap like IE
httpxml = new ActiveXObject('Microsoft.XMLHTTP');
return httpxml;
}
else {
httpxml = null;
}
}
if (httpxml == null) {
document.getElementById('p_status').innerHTML = "Status: Could not create XmlHttpRequest Object,
please upgrade your browser!";
return null;
}
else {
return httpxml;
}
For some reason a function which I haveFor some reason the first function is stopping my second function from working when I click a button which has an onclick even of getMessage().
I know this because I put some alerts into the getMessage() function and they would not excectue until I deleted the first function.
<script type="text/javascript">
function getXmlHttpRequestObject() {
alert("Get XmlHttpObject!");
if (window.XMLHttpRequest)
{
// code for decent browsers such as IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for crap like IE6, IE5
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
else {
document.getElementById('p_status').innerHTML =
"Status: Could not create XmlHttpRequest Object, please upgrade your browser!";
}
//Make variables for later use
var lastMess = 0;
var sendReq = getXmlHttpRequestObject();
var receiveReq = getXmlHttpRequestObject();
var mTimer;
function getMessage() {
alert("Get XmlHttpObject!");
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
alert("Get XmlHttpObject!");
//var url = "scripts/get_data.php?uid=<?=$_SESSION['uid']?>&m=" + lastMess + "&chat=1";
var url = "testXMLdoc.xml";
receiveReq.open("GET", url, true);
receiveReq.onreadystatechange = manageMessage;
receiveReq.send(null);
lastMess++;
}
}
function manageMessage() {
if (receiveReq.readyState == 4) {
var xmldoc = receiveReq.responseXML;
var chat_div = document.getElementById('chat');
var msg_nodes = xmldoc.getElementByTagName("message");
var n_msg = message_nodes.length;
for (i = 0; i < n_msg; i++) {
var sender_node = msg_node[i].getElementByTagName["sender"];
var receiver_node = msg_node[i].getElementByTagName["receiver"];
var time_node = msg_node[i].getElementByTagName["time"];
var text_node = msg_node[i].getElementByTagName["text"];
chat_div.innerHTML = "Here: <br />" + sender_node[0].firstChild.nodeValue + "<br />";
chat_div.innerHTML = reciever_node[0].firstChild.nodeValue + "<br />";
chat_div.innerHTML =time_node[0].firstChild.nodeValue + "<br />";
chat_div.innerHTML = text_node[0].firstChild.nodeValue + "<br />";
}
}
}
</script>
Edit: manageMessage() function doesn't work and I understand why lol.
Problem which is probably causing the main problem:
The alert at the top of this function will not show...
function getXmlHttpRequestObject() {
alert("HTTP XML REQUEST!");
var httpxml;
if (window.XMLHttpRequest)
{
// code decent browsers like Firefox, Chrome, Opera, Safari. And IE7+...
httpxml = new XMLHttpRequest();
return httpxml;
}
else {
if (window.ActiveXObject) {
//Code for crap like IE
httpxml = new ActiveXObject('Microsoft.XMLHTTP');
return httpxml;
}
else {
httpxml = null;
}
}
if (httpxml == null) {
document.getElementById('p_status').innerHTML = "Status: Could not create XmlHttpRequest Object,
please upgrade your browser!";
return null;
}
else {
return httpxml;
}