prasad chitgopekar's Profile

About

 
Points: 0

Contact

 

Drop files in here
or click to pick manually
prasad chitgopekar
July 24, 2015 · Public

prasad chitgopekar
July 24, 2015 · Public

hiii
i was trying to do some ajax tutorials but i am not getting even after following and understanding all videos the output is not getting displayed.

html file : foodpanda.html




**** Food Panda ****





Enter the food you want to order :











php file : foodstore.php




javascript file : foodpanda.js

var xmlHttp = createxmlHttpRequestObject();
// function to create the object
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 object hoss");
}
else{
return xmlHttp;
}
}
// function to actual communication
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{
// if the obj is bsy then time is given to wait 1 sec
setTimeout('process()',1000);
}

}
// after we get response from server what we gonnna do with it
function handleServerResponse(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
// 200 means communication session is ok set
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data;
document.getElementById("underInput").innerHTML=''+message+'';
setTimeout('process()',1000);
}
else{
alert('somthing went wrong!!!!');
}
}
}