Ajax JQuery选择填充
我必须在我的html上添加项目 输入文本“公司”字段和“选择公司”列表 当用户在文本字段中键入时,我希望jQuery使用/Home/SearchSynonym/获取名称并在中显示它,然后选择SearchSynonym获取值user types并执行通配符搜索并返回ID和NAME 有人能帮忙吗,我是新的ti jQueryAjax JQuery选择填充,ajax,jquery,jquery-autocomplete,autofill,Ajax,Jquery,Jquery Autocomplete,Autofill,我必须在我的html上添加项目 输入文本“公司”字段和“选择公司”列表 当用户在文本字段中键入时,我希望jQuery使用/Home/SearchSynonym/获取名称并在中显示它,然后选择SearchSynonym获取值user types并执行通配符搜索并返回ID和NAME 有人能帮忙吗,我是新的ti jQuery Leb您需要澄清SearchSynonym以何种格式返回ID和名称?它是JSON格式的吗?如果是JSON格式,请尝试以下操作: var companyList = $("#Com
Leb您需要澄清SearchSynonym以何种格式返回ID和名称?它是JSON格式的吗?如果是JSON格式,请尝试以下操作:
var companyList = $("#Company_List");
$("#company").change( function(){
$.getJSON("/Home/SearchSynonym/",{ query: $(this).val() }, function(response){
var responseList = "";
$.each(result, function(index, item){
responseList += "<option value='" + item.id + "'>" + item.name + "</option>";
});
companyList.html(responseList);
});
});
如果您的“公司”文本字段在标记删除中带有id=company,您的“公司列表”下拉列表在标记删除中带有id=company\u列表,并且您的服务器端接收到用于提取记录的参数查询,则这将起作用。您可以使用setTimeout。试试这个:
var companyList = $("#Company_List");
$("#company").change( function(){
setTimeout( function() {
$.getJSON("/Home/SearchSynonym/",{ query: $(this).val() }, function(response){
var responseList = "";
$.each(result, function(index, item){
responseList += "<option value='" + item.id + "'>" + item.name + "</option>";
});
companyList.html(responseList);
});
}, 2000);
});
值2000表示延迟2秒。是,SearchSynonym返回JSON,因此如果在用户开始键入公司文本输入时添加代码,Select将填充SearchSynonym查询的返回值?如何延迟搜索?例如,如果使用类型fast,我想延迟大约2秒?您可以使用setTimeout。尝试以下代码:var companyList=$Company\u List$company.change函数{setTimeout函数{$.getJSON/Home/SearchSynonym/,{query:$this.val},functionResponseList{var responseList=;$.eachresult,functionindex,item{responseList+=+item.name+;};companyList.htmlresponseList;};},2000;};setTimeout似乎不想提交查询,我将$company.change更改为$company.keyup。如果没有超时,它将工作Uncaught TypeError:无法调用未定义jquery-2.0.0.js:3907 jquery.fn.extend.val jquery-2.0.0.js:3907匿名函数$.getJSON/Home/SearchSynonym/,{query:$company.val},functionresponse的方法“toLowerCase”,它工作了