N
Nathan
Can I run two XMLHTTPRequest objects at the same time? Im able to get
one to work without problems.
If I put a call to a function inside the first ones onreadystatechange
function, the 2nd ones readyState is always set to 1 (loading). Ive
tried using the same XMLHTTPRequest object, and making a 2nd
XMLHTTPRequest object with the same results. Heres my code thats giving
me problems...
function RefreshChat() {
http.open("GET","refreshchat.php",true);
http.onreadystatechange = function () {
if (http.readyState == 4 && http.status == 200) {
// XML
XML_result = http.responseXML;
docNode = XML_result.documentElement;
msg_count = docNode.getElementsByTagName('message').length;
i = 0;
while(i < msg_count) {
messagesNode = docNode.getElementsByTagName('message');
datetime =
messagesNode.getElementsByTagName('datetime')[0].firstChild.data;
from =
messagesNode.getElementsByTagName('from')[0].firstChild.data;
message =
messagesNode.getElementsByTagName('text')[0].firstChild.data;
FormatMessage(datetime,from,message);
i++;
}
}
}
http.send(null);
setTimeout(RefreshChat,10000);
}
function FormatMessage(datetime,from,message) {
httpnew.open("GET","formatmessage.php",true);
httpnew.onreadystatechange = function() {
if(httpnew.readyState == 4 && httpnew.status == 200) {
alert(httpnew.readyState);
formattedmessage = httpnew.responseText;
document.getElementById('chatarea').innerHTML = formattedmessage;
}
else {
document.getElementById('chatarea').innerHTML = "Error!";
}
}
}
When I run the RefreshChat() function, everything runs fine up to...
httpnew.onreadystatechange = function() {
in the FormatMessage function, because the state never changes
(readyState is always 1).
Both the php pages (refreshchat.php) and (formatmessage.php) exist and
dont timeout or have errors.
one to work without problems.
If I put a call to a function inside the first ones onreadystatechange
function, the 2nd ones readyState is always set to 1 (loading). Ive
tried using the same XMLHTTPRequest object, and making a 2nd
XMLHTTPRequest object with the same results. Heres my code thats giving
me problems...
function RefreshChat() {
http.open("GET","refreshchat.php",true);
http.onreadystatechange = function () {
if (http.readyState == 4 && http.status == 200) {
// XML
XML_result = http.responseXML;
docNode = XML_result.documentElement;
msg_count = docNode.getElementsByTagName('message').length;
i = 0;
while(i < msg_count) {
messagesNode = docNode.getElementsByTagName('message');
datetime =
messagesNode.getElementsByTagName('datetime')[0].firstChild.data;
from =
messagesNode.getElementsByTagName('from')[0].firstChild.data;
message =
messagesNode.getElementsByTagName('text')[0].firstChild.data;
FormatMessage(datetime,from,message);
i++;
}
}
}
http.send(null);
setTimeout(RefreshChat,10000);
}
function FormatMessage(datetime,from,message) {
httpnew.open("GET","formatmessage.php",true);
httpnew.onreadystatechange = function() {
if(httpnew.readyState == 4 && httpnew.status == 200) {
alert(httpnew.readyState);
formattedmessage = httpnew.responseText;
document.getElementById('chatarea').innerHTML = formattedmessage;
}
else {
document.getElementById('chatarea').innerHTML = "Error!";
}
}
}
When I run the RefreshChat() function, everything runs fine up to...
httpnew.onreadystatechange = function() {
in the FormatMessage function, because the state never changes
(readyState is always 1).
Both the php pages (refreshchat.php) and (formatmessage.php) exist and
dont timeout or have errors.