Debt Consolidation - Online Advertising - Lockers - Debt Consolidation - Wp themes

PDA

View Full Version : Javascript Problem with Ajax Request


iliasb
Mar 21st 2008, 3:46 am
Hello Everyone,

I have a "small" problem with java. :-)

I made a Php - Javascipt for displaying the status of my servers.

The Xml response and the php scipt are working fine.
But the Javascipt doesn't do what i want it to do.

I Have 2 Divs in my html (id="1result" and id id="2result"), but my javascipt is only updating "1result"

Firebug is also showing 2 ajax request, but i am only seeing 1 of them. (Without any Errors)

Demo => http://a000008.pixelstudio.eu.com/
Html Source code => Go to demo


//LOAD xmlHttp method.
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

//PARSE DATA
function setmessage(value,org) {
var messageArea = document.getElementById(org + "result");
var fontcolor = "red";
if ( value == 1 ) {
var fontcolor = "green";
var msg = "ONLINE";
} else {
var fontcolor = "red";
var msg = value;
}
messageArea.innerHTML = "<font color=" + fontcolor + ">" + msg + "</font>";
}

//RECIEVE DATA TRUE XML
function callback() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
var value = xmlHttp.responseXML.getElementsByTagName("msg")[0].firstChild.data;
var org = xmlHttp.responseXML.getElementsByTagName("org")[0].firstChild.data;
setmessage(value,org);
}
}
}

//PUSH DATA
function ping_service(value) {
createXMLHttpRequest();
var data = "update.php?id=" + escape(value);
xmlHttp.open("GET", data, true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}



What am i doing wrong ?

Thanks Ilias

Ps: Sorry for my English (Dutch speaking)

zerxer
Mar 22nd 2008, 9:22 am
I'm not a pro at AJAX but what it seems like to me is that it can't handle 2 connections at pretty much the same time. While it still opens the page and you can see this in Firebug, it seems that the javascript doesn't want to call the callback function for both.

Also, this has nothing to do with this but you forgot to close off your DIV tags and the TD tags around them.

iliasb
Mar 22nd 2008, 4:43 pm
I'm not a pro at AJAX but what it seems like to me is that it can't handle 2 connections at pretty much the same time. While it still opens the page and you can see this in Firebug, it seems that the javascript doesn't want to call the callback function for both.

Also, this has nothing to do with this but you forgot to close off your DIV tags and the TD tags around them.

Yes, This is what i mean. But i am still unable to find a solution for the problem. Maybe i have to put everything in array's ?