[Solved] php ajax autocomplete form mysql database


Put this between <HEAD> and </HEAD> put this:

<script src="https://stackoverflow.com/questions/21204158/jquery-2.0.2.js"></script>
<script>
$.customPOST = function(data,callback){
  $.post('search.php',data,callback,'json');
}

$(document).ready(function() {
    $(".search").keyup(function(){
        $.customPOST({search: $.('#searchid').val(),function(response){
         if(response.success){
          var html_code="<div class="show" style="text-align:left;">";
              html_code += '<span class="name">' + response.final_username + '</span>';
              html_code += '&nbsp;<br/>' + response.final_email + '<br/></div>';
          $("#result").text(html_code);
          $("#result").show();
         }
    });

});
</script>

You PHP script must return a JSON response like this way :

<?php
... your code here and ....

$final_username = str_ireplace($q, $b_username, $username);
$final_email = str_ireplace($q, $b_email, $email);

// here we create and return our JSON response
$response = array('final_username' => $final_username, 'final_email' => $final_email);
echo json_encode($response);

?>

solved php ajax autocomplete form mysql database