Advertisement
Guest User

foodstore.js

a guest
Jan 10th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. var xmlHttp = createXmlHttpRequestObject();
  2.  
  3. function createXmlHttpRequestObject() {
  4. var xmlHttp;
  5.  
  6. if(window.ActiveXObject) {
  7. try {
  8. xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
  9. }catch(e) {
  10. xmlHttp = false;
  11. }
  12. }else{
  13. try {
  14. xmlHttp = new XMLHttpRequest();
  15. }catch(e){
  16. xmlHttp = false;
  17. }
  18. }
  19.  
  20. if(!xmlHttp)
  21. alert("cant create that object hoss!");
  22. else
  23. return xmlHttp;
  24. }
  25.  
  26. function process() {
  27. if (xmlHttp.readyState==0 || xmlHttp.readyState==4) {
  28. food = encodeURIComponent(document.getElementById("userInput").value);
  29. xmlHttp.open("GET", "foodstore.php?food=" + food, true);
  30. xmlHttp.onreadystatechange = handleServerResponse;
  31. xmlHttp.send(null);
  32. }else{
  33. setTimeout('process()',1000);
  34. }
  35. }
  36.  
  37. function handleServerResponse() {
  38. if(xmlHttp.readyState==4) {
  39. if(xmlHttp.status==200){
  40. xmlResponse = xmlHttp.responseXML;
  41. xmlDocumentElement = xmlResponse.documentElement;
  42. message = xmlDocumentElement.firstChild.data;
  43. document.getElementById("underInput").innerHTML = '<span style="color:blue">' + message + '</span>';
  44. setTimeout('process()',1000);
  45. }else{
  46. alert('something went wrong!');
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement