title: AJAX logic not working
body: <p>I am new to AJAX and learning it. I am searching a food item in my HTML textbox and trying to communicate with the server to know if the item is available. The respective status of the item should be shown in the div tag below the textbox but it is not showing.</p>
  
  <p>I haven't studied jQuery yet and would like to know the below things:</p>
  
  <ol>
  <li><p>How to get the response from the server in plaintext using AJAX and JavaScript, and display it in the div tag below the textbox (advise the changes to be made in the code).</p></li>
  <li><p>What change should I make in JavaScript code to send the AJAX request in POST method (I know about the changes in PHP code)?</p></li>
  </ol>
  
  <p>//index.html</p>
  
  <p></p>
  
  <pre><code>&lt;head&gt;
    &lt;script type="text/javascript" src="food.js"&gt;
    &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;h3&gt;The Cheff's Place&lt;/h3&gt;
    Enter the food you want to order
  
    &lt;input type="text" id="userInput" name="input" onkeypress="sendInfo()"&gt;&lt;/input&gt;
  
    &lt;div id="underInput"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>//food.js</p>
  
  <pre><code>var request;
  
  function sendInfo() {
    var v = document.getElementById("userInput").value;
    var url = "index.php?food=" + v;
  
    if (window.XMLHttpRequest) {
      request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    }
  
    if (request.readyState == 0 || request.readyState == 4) {
      try {
        request.onreadystatechange = getInfo;
        request.open("GET", url, true);
        request.send(null);
      } catch (e) {
        alert("Unable to connect to server");
      }
    }
  }
  
  function getInfo() {
    if (request.readyState == 4) {
      if (request.status == 200) {
        var val = request.responseText;
        document.getElementById('underInput').innerHTML = val;
      }
    }
  }
  </code></pre>
  
  <p>//index.php</p>
  
  <pre><code>&lt;?php
    header('Content-Type: text/plain');
    $food = $_GET['food'];
    $foodArray = array("paneer", "butter", "chicken", "tandoori", "dal");
    if (in_array($food, $foodArray))
    {
      echo "We do have " .$food;
    }
  
    elseif($food == "")
    {
      echo "Kindly enter some food";
    }
  
    else
    {
      echo "We do not sell " .$food;
    }
  ?&gt;
  </code></pre>