Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Performing live serach using AJAX and PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 318
    Comment on it

    Here in this blog i have used AJAX to search and provide result on the whenever user enter any character in the textbox. The result is coming from a PHP page. Ajax search is used for making the code easy to understand and for saving the users time, here is simple line of AJAX code which search the value from the array and display result in the form of a list. For example a user enter the first letter of string in the text box and it will display the result related to that character.
    Benefits of using Ajax search:
       1. Results are shown as you type in the input box.
       2. Results narrow as you continue typing the text.
       3. If results become too narrow or less, remove characters to see a broader result.

    Html source code :

          <script src=""></script>
                   var val=$("input").val();
                   data :{ character : val},
                      alert("An error occured: " + xhr.status + " " + xhr.statusText);
             span {
                color: green;
          <p><b>Search your favourite tutorials:</b></p>
             <input type = "text">
          <p>Entered Course name: <span id="div"></span></p>

    Here is PHP code:

       // Array with names
       $a[] = "Android";
       $a[] = "B programming language";
       $a[] = "C programming language";
       $a[] = "D programming language";
       $a[] = "euphoria";
       $a[] = "F#";
       $a[] = "GWT";
       $a[] = "HTML5";
       $a[] = "ibatis";
       $a[] = "Java";
       $a[] = "K programming language";
       $a[] = "Lisp";
       $a[] = "Microsoft technologies";
       $a[] = "Networking";
       $a[] = "Open Source";
       $a[] = "Prototype";
       $a[] = "QC";
       $a[] = "Restful web services";
       $a[] = "Scrum";
       $a[] = "Testing";
       $a[] = "UML";
       $a[] = "VB Script";
       $a[] = "Web Technologies";
       $a[] = "Xerox Technology";
       $a[] = "YQL";
       $a[] = "ZOPL";
       $data = $_REQUEST["character"];
       $response = "";
       if ($data !== "") {
          $len = strlen($data);
          $response= "<ul>";
          foreach($a as $name) {
             if (stripos($name,$data)!==false) {
                   $response .= "<li>".$name."</li>";
          $response .= "</ul>";
          echo $response;

    Here is result:

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: