/
DynamicAjaxFunction.php
73 lines (68 loc) · 2.62 KB
/
DynamicAjaxFunction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script>
function RunPhp(serverFile=null,controlId=null,attName='', callId='',device='robot',async=true,timeout='5000') {
document.getElementById("divglobalstatuscontent").innerHTML="loading..";
addLog("I am at RunPhp"+serverFile);
if (serverFile==''|| serverFile==null) {
addLog ("RunPhp : ServerFile Empty");
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.ontimeout = function () {
addLog("The request TimeOut "+serverFile);
document.getElementById("divglobalstatuscontent").innerHTML="time out";
};
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
var address= this.responseText;
if(attName=='')
{
if(controlId !=''&& controlId)
{
document.getElementById(controlId).innerHTML = this.responseText;
}
}
else
{
document.getElementById(controlId).setAttribute(attName,this.responseText);
}
addLog("RunPhp: "+callId+"STATUS="+this.status+",VALUE="+this.responseText);
switch(device)
{
case("robot"):
document.getElementById("divrobotstatusbar").innerHTML = this.responseText;
break;
case("cam"):
document.getElementById("divcamstatusbar").innerHTML = this.responseText;
break;
case("led"):
document.getElementById("divledstatusbar").innerHTML = this.responseText;
break;
case('notification'):
break;
case("move"):
document.getElementById("divmovestatusbar").innerHTML = this.responseText;
break;
case('global'):
break;
default:
document.getElementById("divglobalstatuscontent").innerHTML=this.responseText;
}
document.getElementById("divglobalstatuscontent").innerHTML="Success call";
return true;
}
else{
//request failed.
//document.getElementById("divglobalstatuscontent").innerHTML="...";
}
}
xmlhttp.open("GET",serverFile,async);
xmlhttp.timeout=timeout;
xmlhttp.send();
}
/////////// end Ajax Function RunPhp/////////////
</script>