autocomplete shows all entries, Does not do any searching

后端 未结 2 1489
暖寄归人
暖寄归人 2021-01-29 13:51

Please help me ... I\'m a newbie! Please tell me what to do.

processed.php



        
2条回答
  •  猫巷女王i
    2021-01-29 14:44

    Autocomplete expects the source (when an URL is specified to filter out the results).

    From documentation:

    String: When a string is used, the Autocomplete plugin expects that string to point to a URL resource that will return JSON data. It can be on the same host or on a different one (must provide JSONP). The Autocomplete plugin does not filter the results, instead a query string is added with a term field, which the server-side script should use for filtering the results. For example, if the source option is set to "http://example.com" and the user types foo, a GET request would be made to http://example.com?term=foo. The data itself can be in the same format as the local data described above.

    So in your PHP code you have to do:

    include_once('../../dbConnect.inc.php');
    $sql="SELECT name FROM artist WHERE `name` like '%".mysql_real_escape_string($_GET['term'])."%'";
    $artist = select($sql);
    $output_items = array();
    while($row = mysql_fetch_array($artist)) {
        $results[] = array('label' => $row['name']);
    }
    echo json_encode($results);
    

提交回复
热议问题