OSDN Git Service

for CLEM
[vem/WITs.git] / JS / unused / Currentcondition.js~
1 function Currentcondition(command) {
2
3  var ajax=getAjax();
4  
5  if(command == "request"){
6         var position1 = document.getElementById("Position");
7         var magnificant = document.getElementById("Magnificant");
8         var brightness = document.getElementById("Brightness");
9         var contrast = document.getElementById("Contrast");
10         var forcus = document.getElementById("Forcus");
11         var voltage = document.getElementById("Voltage");
12   }else {
13         var position1 = document.anchorsgetElementById("result");
14   }
15   
16   if (ajax) {
17          try{
18            ajax.onreadystatechange = getData;
19          }catch(e){
20       position1.innerHTML="Onreadystate change error.";          
21          }
22          
23          try{
24       ajax.open("GET","//localhost:8000/cgi-bin/vemclient.rb?command="+encodeURIComponent(command),true);
25          }catch(e){
26       position1.innerHTML = "ajax open error";
27          }
28
29     try {
30          ajax.send(null);
31     }catch (e) {
32       position1.innerHTML ="send error";
33     }
34     
35   }else {
36         position1.innerHTML = "you cannot use ajax....";
37   }
38   
39   function getData() { 
40       if (ajax.readyState==4) {
41           if (ajax.status==200) {
42                      console.log("Hello!");
43                      
44                      var resultjson = ajax.responseText;
45                      resultjson=JSON.parse(resultjson);
46                       console.log(typeof resultjson);
47   /*
48                      for (key in resultjson) {
49                      console.log(key+":"+resultjson(key));
50                   }
51                   */
52                      //position1.innerHTML=resultjson;
53                      
54                      position1.innerHTML = "x="+resultjson["Current_stageX"]+" y="+resultjson['Current_stageY']+" z="+resultjson['Current_stageZ']+" a="+resultjson['Current_stageA'];
55                magnificant.innerHTML = "Magnificant:"+resultjson['Magnificant'];
56                brightness.innerHTML = "Brightness:"+resultjson['Brightness'];
57                contrast.innerHTML = "Contrast:"+resultjson['Contrast'];
58                forcus.innerHTML = "Forcus:"+resultjson['Forcus'];
59                voltage.innerHTML = "Voltage:"+resultjson['Voltage'];                 
60             //   result.innerHTML = ajax.responseText; 
61              }else {
62                position1.innerHTML = "HTTP transmission....";
63             }
64        }
65   }
66  }