-
Notifications
You must be signed in to change notification settings - Fork 0
/
foodstore.js
44 lines (40 loc) · 1.14 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
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
if(!xmlHttp)
alert("can't create object!");
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.open("GET", "food="+food, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}else{
setTimeout('process()',1000);
}
}
function handleServerResponse(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
console.log('run..');
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data;
//message = xmlHttp.responseXML.documentElement.firstChild.data;
//console.log(message);
document.getElementById("underInput").innerHTML = '<span style = "color:blue">' + message + '</span>';
setTimeout('process()',1000);
}else{
alert('Something went wrong!');
}
}
}