-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoodstore.js
80 lines (47 loc) · 1.24 KB
/
foodstore.js
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
74
75
76
77
78
79
80
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject();
{
var xmlHttp;
if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp = false;
}
else{
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
}
}
if(!xmlHttp){
alert("cant create that");
else
return xmlHttp;
}
}
function process(){
if(xmlHttp.readyState=0||xmlHttp.readyState=4){
food = encodeURIComponent(document.getElementById('userinput').value);
xmlHttp.open("GET","foodstore.php?food= "+food,true);
xmlHttp.onreadystatechange=handleServerResponse;
xmlHttp.send(null);
}else{
setTimeout('process()',1000);
}
}
function handleServerResponse(){
if(xmlHttp.readyState=4){
if(xmlHttp.status=200){
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message= xmlDocumentElement.firstChild.data;
document.getElementById("underinput").innerHTML = '<span style="color:blue">' + message + '</span>'
setTimeout('process()',1000);
}else{
alert("something went wrong");
}
}
}