gpt4 book ai didi

php - 为什么 jQuery 和 PHP 的多项选择自动完成不起作用?

转载 作者:行者123 更新时间:2023-11-29 06:57:48 25 4
gpt4 key购买 nike

我想使用 multiple autocomplete在我的表单中使用 jQuery、PHP 和 MySQL。但这对我不起作用。我有什么错误吗?


HTML 代码:

<input type="text" id="country" name="country" />

jQuery 代码:

$( "#countries" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})

.autocomplete({
source: function( request, response ) {
$.getJSON( "process/find_countries.php", {
term: extractLast( request.term )
}, response );
},
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});

PHP代码

    $result = array();
$term = strtolower($_GET["term"]);
$sql = "SELECT title FROM tbl_countries WHERE title LIKE ?";
$q = $db->prepare($sql);
$q->execute(array('%'.$term.'%'));
$rows = $q->rowCount();
echo($rows);
while ($r = $q->fetch())
{
array_push($result,array('label'=>$r['title'], 'value'=>$r['title']));
}
echo json_encode($result);

最佳答案

查看来自服务器的 Firebug 响应。以及为什么要这样做 echo($rows); ?

关于php - 为什么 jQuery 和 PHP 的多项选择自动完成不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11688802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com