【发布时间】:2014-08-26 16:37:44
【问题描述】:
我正在使用 jquery 自动完成功能创建搜索栏。
这是我的自动完成代码:
$('#search_bar input#search_box').autocomplete({
source: function( request, response ) {
$.ajax({
url: "service/search.php",
type: "POST",
data: {action:'getSuggest',categoryId:$('#search_bar #selectSearch').val(),searchText:request.term},
dataType: "json",
cache: false,
success: function( data ) {
response( $.map( data['0'], function( Convalue ) {
return {
label: Convalue['name'],
value: Convalue['name'],
id: Convalue['ID']
}
}));
},
error: function (e,a,b) {
jAlert('error in searching products'+e,'Failed');
}
});
},
cacheLength: 0,
minLength: 1,
select: function( event, ui ) {
event.preventDefault();
$('#search_bar input#search_box').val();
if(ui.item)
{
var categoryId=$('#search_bar #selectSearch').val();
if(categoryId=='0'){
if(ui.item.id=='1')
location.replace('custom-granule.php');
else if(ui.item.id=='2')
location.replace('custom-raw.php');
else
location.replace('product-info.php?id='+ui.item.id);
}
else if(categoryId=='1')
location.replace('product-symptom.php?id='+ui.item.id);
else if(categoryId=='2')
location.replace('product-pattern.php?patternId='+ui.item.id);
else
location.replace('product-category.php?id='+ui.item.id);
}
else {
jAlert("Nothing selected, input was " + this.value);
}
}
});
现在我的问题是:IE 和 Chrome 在搜索时显示警报消息“搜索框为空”。 IE 和 chrome 在显示此警告框时不一致。有时显示,有时不显示。 FF好像还可以。
【问题讨论】:
标签: jquery autocomplete jquery-autocomplete