在ASP.Net中使用jQuery AutoComplete未找到匹配项时清除AutoComplete文本框 $(函数(){ $('[id*=txteno]')。提前键入({ 提示:没错, 推荐理由:没错, 最小长度:1, 来源:功能(请求、响应){ $.ajax({ url:“”, 数据:“{'前缀':'”+请求+“}”, 数据类型:“json”, 类型:“POST”, contentType:“应用程序/json;字符集=utf-8”, 成功:功能(数据){ 如果(数据长度>0){ 项目=[]; map={}; $.each(data.d,function(i,item){ 变量id=项目分割('-')[1]; var name=item.split('-')[0]; map[name]={id:id,name:name}; 项目。推送(名称); }); 答复(项目); } 否则{ 响应([{name:'未找到结果',项:-1}]); } }, 错误:函数(响应){ 警报(response.responseText); }, 故障:功能(响应){ 警报(response.responseText); } }); }, 更新程序:函数(项){ $('[id*=hfEnoId]').val(映射[item].id); 退货项目; } }); });
现在我想要的是,当用户继续在文本框中输入时,过滤结果会附加到文本框中,这很好。如果用户键入的字符与结果不匹配,则我希望清除该字符并显示为“未找到结果”在ASP.Net中使用jQuery AutoComplete未找到匹配项时清除AutoComplete文本框 $(函数(){ $('[id*=txteno]')。提前键入({ 提示:没错, 推荐理由:没错, 最小长度:1, 来源:功能(请求、响应){ $.ajax({ url:“”, 数据:“{'前缀':'”+请求+“}”, 数据类型:“json”, 类型:“POST”, contentType:“应用程序/json;字符集=utf-8”, 成功:功能(数据){ 如果(数据长度>0){ 项目=[]; map={}; $.each(data.d,function(i,item){ 变量id=项目分割('-')[1]; var name=item.split('-')[0]; map[name]={id:id,name:name}; 项目。推送(名称); }); 答复(项目); } 否则{ 响应([{name:'未找到结果',项:-1}]); } }, 错误:函数(响应){ 警报(response.responseText); }, 故障:功能(响应){ 警报(response.responseText); } }); }, 更新程序:函数(项){ $('[id*=hfEnoId]').val(映射[item].id); 退货项目; } }); });,jquery,asp.net,ajax,vb.net,autocomplete,Jquery,Asp.net,Ajax,Vb.net,Autocomplete,现在我想要的是,当用户继续在文本框中输入时,过滤结果会附加到文本框中,这很好。如果用户键入的字符与结果不匹配,则我希望清除该字符并显示为“未找到结果” 您是否也可以添加response方法?response([{name:'No results found',item:-1}])当我添加了警报(response.responseText)时,它已经在那里了它在按键时显示为Undefined,在下拉菜单中动态获取值,那么如何获取json值呢?另外,向我们展示函数响应,以及您在该函数中所做的操作。。
您是否也可以添加
response
方法?response([{name:'No results found',item:-1}])代码>当我添加了警报(response.responseText)时,它已经在那里了
它在按键时显示为Undefined
,在下拉菜单中动态获取值,那么如何获取json值呢?另外,向我们展示函数响应,以及您在该函数中所做的操作。。如何分配从搜索中获取的数据。
<script type="text/javascript">
$(function () {
$('[id*=txteno]').typeahead({
hint: true,
highlight: true,
minLength:1,
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/VB.aspx/GetEno") %>',
data: "{ 'prefix': '" + request + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d.length > 0) {
items = [];
map = {};
$.each(data.d, function (i, item) {
var id = item.split('-')[1];
var name = item.split('-')[0];
map[name] = { id: id, name: name };
items.push(name);
});
response(items);
}
else {
response([{ name: 'No results found.', item: -1 }]);
}
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
updater: function (item) {
$('[id*=hfEnoId]').val(map[item].id);
return item;
}
});
});
</script>