Javascript jquery自动完成输入字段无任何操作
我想实现一个自动完成输入字段,但当我开始插入一些文本时,什么也没有发生,一秒钟内“忙圈”就出现了,仅此而已。 这是我的密码: html> $db->setQuery($query) $product_name=$db->loadResult() 错误控制台为空Javascript jquery自动完成输入字段无任何操作,javascript,php,jquery,autocomplete,Javascript,Php,Jquery,Autocomplete,我想实现一个自动完成输入字段,但当我开始插入一些文本时,什么也没有发生,一秒钟内“忙圈”就出现了,仅此而已。 这是我的密码: html> $db->setQuery($query) $product_name=$db->loadResult() 错误控制台为空 感谢您的建议您的服务器端代码不会返回插件所需的数据。 有关来源的文档中选项 使用字符串时,Autocomplete插件希望该字符串 指向将返回JSON数据的URL资源 您的search.php脚本必须返回要向用户建议的项目(显示在自动完成
感谢您的建议您的服务器端代码不会返回插件所需的数据。 有关来源的文档中选项 使用字符串时,Autocomplete插件希望该字符串 指向将返回JSON数据的URL资源 您的
search.php
脚本必须返回要向用户建议的项目(显示在自动完成列表中)
这是一个例子:
/*term is a parameter generated by the plugin and contains
the string the user has typed in the input*/
$_GET['term'] = isset($_GET['term']) ? $_GET['term'] : null;
//manage your own query depending on your database and preferred way for db interactions
//$query = "select product_name from product where product_name like ?";
//$term = "%{$_GET['term']}%";
//$stmt = $mysqli->prepare($query);
//$stmt->bind_param("s", $term);
//$stmt->execute();
//$result = $stmt->get_result();
$autocompleteList = [];
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$autocompleteList[] = $row['product_name'];
}
die(json_encode($autocompleteList));
服务器端代码不会返回插件所需的数据。 有关来源的文档中选项 使用字符串时,Autocomplete插件希望该字符串 指向将返回JSON数据的URL资源 您的
search.php
脚本必须返回要向用户建议的项目(显示在自动完成列表中)
这是一个例子:
/*term is a parameter generated by the plugin and contains
the string the user has typed in the input*/
$_GET['term'] = isset($_GET['term']) ? $_GET['term'] : null;
//manage your own query depending on your database and preferred way for db interactions
//$query = "select product_name from product where product_name like ?";
//$term = "%{$_GET['term']}%";
//$stmt = $mysqli->prepare($query);
//$stmt->bind_param("s", $term);
//$stmt->execute();
//$result = $stmt->get_result();
$autocompleteList = [];
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$autocompleteList[] = $row['product_name'];
}
die(json_encode($autocompleteList));
在最后的php文件中回显$product_名称。实际上,您没有从中得到任何东西。您的search.php代码?输入字段中没有任何内容,只有我在搜索php代码之后第二次显示product的第一个值:$query='database data'$db->setQuery($query)$product_name=$db->loadResult();在最后的php文件中回显$product_名称。实际上,您没有从中得到任何东西。您的search.php代码?输入字段中没有任何内容,只有我在搜索php代码之后第二次显示product的第一个值:$query='database data'$db->setQuery($query)$product_name=$db->loadResult();
$query = 'database data';
/*term is a parameter generated by the plugin and contains
the string the user has typed in the input*/
$_GET['term'] = isset($_GET['term']) ? $_GET['term'] : null;
//manage your own query depending on your database and preferred way for db interactions
//$query = "select product_name from product where product_name like ?";
//$term = "%{$_GET['term']}%";
//$stmt = $mysqli->prepare($query);
//$stmt->bind_param("s", $term);
//$stmt->execute();
//$result = $stmt->get_result();
$autocompleteList = [];
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$autocompleteList[] = $row['product_name'];
}
die(json_encode($autocompleteList));