我已经为搜索模块使用了ajax-jquery自动完成功能,但是当我输入单个字符时,需要一些时间才能加载数据,如何快速创建并使下拉浮动平滑...
请咨询
ajax代码
mysql_connect("localhost","root","");
mysql_select_db("1234");
$searcho=$_GET["term"];
$query=mysql_query("SELECT * FROM sltdb_cddir_content where title like '%".$searcho."%'AND categories_id=80 order by title ASC ");
$json=array();
while($display=mysql_fetch_array($query)){
$json[]=array(
'value'=> $display["title"],
'label'=>$display["title"]
);
}
echo json_encode($json);
jquery
jQuery(function(){
jQuery( "#addresso" ).autocomplete({
source: function( request, response ) {
jQuery.ajax({
url: "<?php echo JURI::root().'modules/mod_jomdirectory_search/tmpl/org-address.php'; ?>",
dataType: "json",
data: {
searcho : jQuery('#searcho').val(),
addresso : jQuery('#addresso').val()
},
success: function( data ) {
response( jQuery.map( data, function( item ) {
return {
label: item.addresso ,
value: item.addresso
}
}));
}
});
},
minLength: 1
});
});