title: AJAX Showing result a few seconds only then gone
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function showUser(str) {
      if (str == "") {
          document.getElementById("res").innerHTML = "";
          return;
      } else { 
          if (window.XMLHttpRequest) {
              // code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp = new XMLHttpRequest();
          } else {
              // code for IE6, IE5
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
          xmlhttp.onreadystatechange = function() {
              if (this.readyState == 4 &amp;&amp; this.status == 200) {
                  document.getElementById("res").innerHTML = this.responseText;
              }
          };
          xmlhttp.open("GET","search.php?q="+str,true);
          xmlhttp.send(null);
    return false;
      }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $q = intval($_GET['q']);
  
  include 'connect.php';
  if (!$con) {
      die('Could not connect: ' . mysql_error($con));
  }
  
  $rs=mysql_query("select * from webuser where FirstName LIKE '%".$q."%' or MiddleName LIKE '%".$q."%' or LastName LIKE '%".$q."%' or address LIKE '%".$q."%' or contactno LIKE '%".$q."%'
      or department LIKE '%".$q."%' or position LIKE '%".$q."%' or username LIKE '%".$q."%'",$con);
  if(!$rs) { 
      die(mysql_error()); // TODO: better error handling
   echo '&lt;script&gt;alert(mysql_error())&lt;/script&gt;';
  }
  else{
     //code to print here
  }
  mysql_close($con);
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have a problem with my code, ajax shows the result but in just a second or less then disappear. Tried searching, nothing found. Thanks in advance. </p>