こんにちは私は問題に遭遇しました。私はjquerysの有名なオートコンプリートを実装し、データベースからリスト(かなり長い)を作成してオートコンプリートフィールドに出力しています。しかし、リストから正しい値を見つけるのに時間がかかりすぎています。誰かが私がこれをスピードアップできる方法を知っていますか?これが私のjqueryです:
<script>
$(function() {function log( message ) {$( "#destId" ).val( message );}
$( "#destinations" ).autocomplete({
source: "destinos.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"" + ui.item.id :
"" + this.value );}});});
</script>
そしてここにdestinos.phpがあります:
//connect to database
include 'php/dbconn.php';
$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends
$qstring = "SELECT Destination as value, DestinationId as id FROM DestinationId WHERE Destination LIKE '%".$term."%'";
//query the database for entries containing the term
$result = mysql_query($qstring);
//loop through the retrieved values
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$row['value']=htmlentities(stripslashes($row['value']));
$row['id']=htmlentities(stripslashes($row['id']));
$row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
どんな助けでも大歓迎です!