我有(2)jquery自动完成控件背对背。当我在第一个框中输入并选择一个值,然后在第二个框中输入并选择一个值时,一切进展顺利。如果我然后返回到第一个文本框并输入一个值,我将从第二个自动完成控件获取错误消息。
有什么想法吗? 这是第一个文本框
$("#txtCIPCriteria").autocomplete({
source: function (request, response) {
$.ajax({
async: false,
delay: 250,
url: $('#hdfldPath').val(),
data: "{ 'Name': '" + request.term.replace(/'/g, "\&apos") + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('|')[0],
val: item.split('|')[1]
//label: item.Text,
//value: item.Value
} // end of return
})) // end of response
} // end of success
}); // end of ajax
}, // end of source
select: function (e, i) {
$("#hdfldCIPCode").val(i.item.val);
},
change: function (event, ui) {
if (!ui.item) {
$(event.target).val('');
}
},
minLength: 2
}); // end of $("#txtCIPCriteria").autocomplete
这是第二个控件
$("#txtBuildingsCriteria").autocomplete({
source: function (request, response) {
$.ajax({
async: false,
delay: 250,
url: $('#hdfldPath').val(),
data: "{ 'Name': '" + request.term.replace(/'/g, "\&apos") + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('|')[0],
val: item.split('|')[1]
//label: item.Text,
//value: item.Value
} // end of return
})) // end of response
} // end of success
}); // end of ajax
}, // end of source
select: function (e, i) {
$("#hdfldBuilding").val(i.item.val);
// GetFiscalAgents1(i.item.val);
var CipCode = $('#hdfldCIPCode').val();
var Bldg = $("#hdfldBuilding").val();
var ProgType = $('#ddlProgramType').val();
GetFiscalAgents1(i.item.val);
GetProspRegion(i.item.val);
//var Result = FindCIPCodeCount(CipCode, Bldg, ProgType)
//if (Result == 'Exists') {
// MsgBox('This is an active CIPCode, Building and ProgramType combination already. Please change your criteria.');
//}
//else {
// $("#hdfldBuilding").val(i.item.val);
// GetFiscalAgents1(i.item.val);
// GetProspRegion(i.item.val);
//}
},
change: function (event, ui) {
if (!ui.item) {
$(event.target).val('');
}
},
minLength: 3
}); // end of $("#txtBuildingsCriteria").autocomplete
答案 0 :(得分:0)
尝试将cache: false
置于ajax函数