Code has been added to clipboard!

PHP AJAX Live Search

Example
<html>
<head>
<script>
  function showResult(str) {
    if (str.length == 0) { 
      document.getElementById('live_search').innerHTML = '';
      document.getElementById('live_search').style.border = '0px';
      return;
    }
    if (window.XMLHttpRequest) {
      // script for browser version above IE 7 and the other popular browsers (newer browsers)
      xmlhttpreq=new XMLHttpRequest();
    } else { 
      // script for the IE 5 and 6 browsers (older versions)
      xmlhttpreq=new ActiveXObject('Microsoft.XMLHTTP');
    }
    xmlhttpreq.onreadystatechange = function() {
      //check if server response is ready  
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("live_search").innerHTML=this.responseText;
        document.getElementById("live_search").style.border="1px solid #A5ACB2";
      }
    }
    xmlhttpreq.open("GET", "/learn/livesearch.php?q="+str, true);
    xmlhttpreq.send();
  }
</script>
</head>
<body>

<form>
  <input type="text" size="30" onkeyup="showResult(this.value)">
  <div id="live_search"></div>
</form>

</body>
</html>