dqc18251 2015-08-30 15:17
浏览 57

无法在javascript上读取函数

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()">
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求lingo代码和思路
    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)