title: Made an AJAX script that is supposed to use GET to fetch data using my PHP file, not working
body: <p>The code is supposed to fetch the query result and display it according to the number written in the text box, i tried (onkeydown and onkeyup) and both didn't work, i have no idea why it is not working and what is my mistake.</p>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;script&gt;
          function showRoom(rid) {
              xmlhttp = new XMLHttpRequest();
  
              xmlhttp.open("GET", "getRoomAJAX.php?q="+rid, true);
              xmlhttp.send();
  
              xmlhttp.onreadystatechange = function () {
                  if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
                      document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                  }
              }
          }
      &lt;/script&gt;
  
      &lt;form&gt; 
          &lt;input type="text" name="rid" onkeydown="showRoom(this.value)"&gt;
      &lt;/form&gt;
  
      &lt;div id="txtHint"&gt;Room...&lt;/div&gt;
  </code></pre>
  
  <p>getRoomAJAX.php code:</p>
  
  <pre><code>&lt;?php
  session_start();
  ob_start();
  
  $q = $_GET["q"];
  
  $db = new Database();
  $dbc = $db-&gt;getConnection();
  
  if (!$dbc) {
      die('Could not connect: ' . mysql_error());
  }
  
  $query = "SELECT * FROM indvProj_room WHERE rid = '".$q."'";
  
  $result = mysqli_query($dbc, $query);
  
  //start creating the table HTML
  if ($result) {
      echo "&lt;table border='1' align='center' cellspacing = '2' cellpadding = '4' width='100%'&gt;
            &lt;tr&gt;
            &lt;th&gt;&lt;b&gt;Room ID&lt;/b&gt;&lt;/th&gt;
            &lt;th&gt;&lt;b&gt;Room Description&lt;/b&gt;&lt;/th&gt;
            &lt;/tr&gt;";
      while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
          echo "&lt;tr&gt;";;
          echo "&lt;td&gt;" . $_SESSION['adminRoomChoice'] = $row['rid'] . "&lt;/td&gt;";
          echo "&lt;td&gt;" . $row['roomDesc'] . "&lt;/td&gt;";
          echo "&lt;/tr&gt;";
      }
      echo "&lt;/table&gt;";
  } else {
      echo '&lt;p class="error"&gt;Sorry, cannot find the room, are you sure of the entered Room ID?&lt;/p&gt;';
      echo '&lt;p class = "error"&gt;' . mysqli_error($dbc) . '&lt;/p&gt;';
  }
  
  
  ?&gt;
  </code></pre>