-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoodstore.js
60 lines (55 loc) · 1.2 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
var xmlHttp=createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
//alert("Hello");
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("Can't create that object");
}
else{
//alert("Hello");
return xmlHttp;
}
}
function process(){
//alert(xmlHttp.readyState());
//alert("hekko");
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');
}
}
}