18 Mayıs 2015 Pazartesi

Ajax ile otomatik arama

HTML
<input type="text" placeholder="ara" onkeyup="getir(this.value)" >
    <div class="sonuclar"></div>
JS
function getir(value){
    $.post("init.php",{phpValue:value},function(data){
        if (value != "") {
            $(".sonuclar").html(data);
        }else{
            $(".sonuclar").html("");
        }
    })

}   

PHP
<?php
mysql_select_db("people",mysql_connect("localhost","root",""));

$phpValue = $_POST['phpValue'];

$ara = mysql_query("select sirket from kisi where sirket like '$phpValue%'");
while ($row = mysql_fetch_array($ara)) {
    echo "<div>".$row["sirket"]."</div>";
}


?>

Hiç yorum yok:

Yorum Gönder