Advertisement
cyphric

store.js

May 14th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 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. }else{
  12. try{
  13. xmlHttp = new XMLHttpRequest();
  14. }catch(e){
  15. xmlHttp = false;
  16. }
  17. }
  18.  
  19.  
  20. if(!xmlHttp)
  21. alert("Can't 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", "store.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.  
  45. }else{
  46. alert('Something went wrong!');
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement