我正在开发一个自动完成选项进行集成。自动完成工作正常。但是当我添加另一个参数变量时,自动完成功能无效,猜猜有点语法问题。在下面附带的脚本中,我需要将变量countrycode传递给fetch_customers.php
$(document).ready(function($) {
$("#customers").autocomplete({
var countrycode = '<?php echo $agencyid; ?>';
data: {
countrycode: countrycode
},
source: "fetch_customers.php",
minLength: 2,
select: function(event, ui) {
var url = ui.item.id;
if (url != '#') {
location.href = '/view-customer/' + url;
}
},
// optional (if other layers overlap autocomplete list)
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
});
您的语法无效。你需要在你提供给countrycode
的对象之外定义autocomplete()
。
话虽如此,那不是你在jQueryUI自动填充请求中传递数据的方式。您需要传递您调用的URL的查询字符串中的值:
$(document).ready(function($) {
$("#customers").autocomplete({
source: "fetch_customers.php?countrycode=<?php echo $agencyid; ?>",
minLength: 2,
select: function(event, ui) {
var url = ui.item.id;
if (url != '#') {
location.href = '/view-customer/' + url;
}
},
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
});