如何使用ajax自动完成[关闭]

im using autocomplete of jqueryui (http://jqueryui.com/autocomplete/#remote) and the source comes from "source: "search.php""

This code ...

 $( "#name" ).autocomplete({
source: "search.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
}); 

.. And this code below together works perfectly fine!
but autocomplete suggest me "All of my Data" ! not smth like my term.

<?php
require('inc/tunel.php');
$keyword = $_POST['keyword'];
$respons = array();
$fetch_engine = $db->query("SELECT name FROM `engine`");
    while($read_engine = $fetch_engine->fetch(PDO::FETCH_ASSOC)) {
        $respons[] = $read_engine['name'];
        }

        echo json_encode($respons);
 ?>

i also tried this code below, my problem solved, but i dont want to see my data in "view source" of my document!

$( "#name" ).autocomplete({
source: <?php
    require('inc/tunel.php');

    $respons = array();
    $fetch_engine = $db->query("SELECT name FROM `engine`");
        while($read_engine = $fetch_engine->fetch(PDO::FETCH_ASSOC)) {
            $respons[] = $read_engine['name'];
            }
            
            echo json_encode($respons);
            

?>,
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
}); 

</div>

You should create a local service that accepts a parameter with a substring (in my example parameter q with at least 2 chars) and returns a json with the possible tags, and then use it into the source of the autocomplete as an ajax call.

    $( "#name" ).autocomplete({
          source: function( request, response ) {
           $.ajax({
              url: "http://yourwebservice.com/search",
              dataType: "jsonp",
              data: {
                q: request.term
              },
              success: function( data ) {
                response( data );
              }
            });
          },
          minLength: 2
        });