我已经完成了jQuery自动完成脚本的工作。该脚本运行正常。但是,当响应为“未找到结果”时,不应激活location.href。在这种情况下,location.href就在那里。
jQuery:
$(document).ready(function($) {
$("#customers").autocomplete({
source: "/core/country/fetch_customers.php?cc=<?php echo $agencyid; ?>",
minLength: 2,
select: function(event, ui) {
var code = ui.item.id;
if (code != '#') {
location.href = '/view-customer/' + code;
}
},
response: function(event, ui) {
if (!ui.content.length) {
var noResult = {
value: "",
label: "No results found"
};
ui.content.push(noResult);
}
},
// optional (if other layers overlap autocomplete list)
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
});