I have here a javascript code which contains four main function. Every function runs different php files. This code is running when I have only two function but when I tried to add more.. the function in javascript is not working anymore. I am new to this kind of programming which calls php using javascript so I have no idea why is that when I am adding more functions it do not work anymore. Here is my javascript file.
var xmlHttp = createXmlHttpRequestObject();
var nIntervalId;
var underInput;
var x;
var y;
var z;
function process () {
nIntervalId = setInterval(checkUpdate1, 1000);
checkUpdate1 ();
checkUpdate2 ();
nIntervalId1 = setInterval(checkUpdate3, 1000);
checkUpdate3 ();
checkUpdate4 ();
}
function checkUpdate1 () {
xmlHttp.open("GET", "../php-files/checkupdate.php?t="+Math.random(), true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send();
}
function checkUpdate2 () {
xmlHttp.open("GET", "../php-files/checkreport.php?t="+Math.random(), true);
xmlHttp.onreadystatechange = handleServerResponse1;
xmlHttp.send();
}
function checkUpdate3 () {
xmlHttp.open("GET", "../php-files/checkupdateambulance.php?t="+Math.random(), true);
xmlHttp.onreadystatechange = handleServerResponse3;
xmlHttp.send();
}
function checkUpdate4 () {
xmlHttp.open("GET", "../php-files/checkupdateambulance1.php?t="+Math.random(), true);
xmlHttp.onreadystatechange = handleServerResponse4;
xmlHttp.send();
}
function handleServerResponse3 () {
//console.log(xmlHttp.readyState);
underInput = encodeURIComponent(document.getElementById("underInput3").innerHTML);
if ( xmlHttp.readyState==4 )
if ( xmlHttp.status==200) {
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.textContent;
message1 = parseInt(message);
underInput = parseInt(underInput);
if ( message1 > underInput ) {
document.getElementById("notification-ambulance").style.backgroundColor = "#ED2D2D";
}
document.getElementById("underInput3").innerHTML = message;
x = document.getElementById("underInput3").innerHTML;
z= x - y;
if(z>0){
document.getElementById("underInput5").innerHTML = z;
}
}
}
function handleServerResponse4 () {
//console.log(xmlHttp.readyState);
underInput = encodeURIComponent(document.getElementById("underInput4").innerHTML);
if ( xmlHttp.readyState==4 )
if ( xmlHttp.status==200) {
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.textContent;
message1 = parseInt(message);
underInput = parseInt(underInput);
if ( message1 > underInput ) {
alert("Sad");
}
document.getElementById("underInput4").innerHTML = message;
y = document.getElementById("underInput4").innerHTML;
}
}
function handleServerResponse () {
//console.log(xmlHttp.readyState);
underInput = encodeURIComponent(document.getElementById("underInput").innerHTML);
if ( xmlHttp.readyState==4 )
if ( xmlHttp.status==200) {
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.textContent;
message1 = parseInt(message);
underInput = parseInt(underInput);
if ( message1 > underInput ) {
document.getElementById("notification").style.backgroundColor = "#ED2D2D";
}
document.getElementById("underInput").innerHTML = message;
x = document.getElementById("underInput").innerHTML;
z= x - y;
if(z>0){
document.getElementById("underInput2").innerHTML = z;
}
}
}
function handleServerResponse1 () {
//console.log(xmlHttp.readyState);
underInput = encodeURIComponent(document.getElementById("underInput1").innerHTML);
if ( xmlHttp.readyState==4 )
if ( xmlHttp.status==200) {
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.textContent;
message1 = parseInt(message);
underInput = parseInt(underInput);
if ( message1 > underInput ) {
alert("Sad");
}
document.getElementById("underInput1").innerHTML = message;
y = document.getElementById("underInput1").innerHTML;
}
}
function createXmlHttpRequestObject() {
var xmlHttp;
if (window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsofot.XMLHTTP");
} catch (e) {
xmlHttp = false;
}
}else{
try{
xmlHttp = new XMLHttpRequest();
} catch (e) {
xmlHttp = false;
}
}
if (!xmlHttp) {
alert("Could not create XML Object");
} else {
return xmlHttp;
}
}
Here is where I call my process function:
<body onload = "process()">