带有ajax和查询的实时搜索引导程序

Me and some mates have been trying to make a live search script on our search bar. Now this isn't going that well so now we are asking for ur help!

our external file to get the results is this :

$con = mysqli_connect('localhost', '*', '*', '*');

$key=$_POST['search'];

$query = ("select name, url from search where name LIKE '%{$key}%'");
$sql = $con->query($query);

while($row = $sql->fetch_array()){
    echo json_encode($row);
}

and our script code looks like this :

        <script>

    $(document).ready(function(){

$( "#formGroupInputLarge" ).keyup(function() {
  console.log( "Handler for .keyup() called." )
        var string = $('#formGroupInputLarge').val();
            $.ajax(
                {
                    type: 'POST',
                    url: 'search.php',
                    data: {'search': string},
                    success: function(data){
                        var text= JSON.parse(data);
            $("#suggesstion-box").show();
            $("#suggesstion-box").html("<a href='#'>"+ text +"</a>");
            $("#search-box").css("background","#FFF");
        }
                }
            );
        }); 

    });
    </script>

we've tried with multiple things like the next ones :

<script>

$(document).ready(function () {

    $("#formGroupInputLarge").keyup(function () {
        console.log("Handler for .keyup() called.");
        var string = $('#formGroupInputLarge').val();
        $.ajax(
            {
                type: 'POST',
                url: 'search.php',
                data: {'search': string},
                success: function (data) {

                    var obj = eval('('+ data +')' );
                    console.log(obj['name']);
                    //var text = JSON.parse(data);
                    //$("#suggesstion-box").show();
                    //$("#suggesstion-box").html(text);
                    //$("#search-box").css("background", "#FFF");
                }
            }
        );
    });

});

</script>

but none of it seems to work. Please help us!

So many things could be wrong in your code ! You need to give more info on how each part behaves (error messages, etc).

Check this to get a good look at how everything work with AJAX, and nice and simple examples http://www.w3schools.com/php/php_ajax_intro.asp