Javascript 基于自动完成值的动态下拉列表
我试图根据用户在上一个文本框Auto complete中插入的值填充动态下拉列表。因此,当用户在“自动完成”文本框中插入演员/女演员名称时,下拉列表将由该演员所演电影的列表填充 问题: 有人能告诉我这个代码有什么问题吗?为什么它会填充一个空下拉列表 以下是html/js代码:Javascript 基于自动完成值的动态下拉列表,javascript,php,jquery,drop-down-menu,autocomplete,Javascript,Php,Jquery,Drop Down Menu,Autocomplete,我试图根据用户在上一个文本框Auto complete中插入的值填充动态下拉列表。因此,当用户在“自动完成”文本框中插入演员/女演员名称时,下拉列表将由该演员所演电影的列表填充 问题: 有人能告诉我这个代码有什么问题吗?为什么它会填充一个空下拉列表 以下是html/js代码: <html> <?php print_r($_POST); ?> <head> <link rel="stylesheet" href="http://ajax.googleapi
<html>
<?php
print_r($_POST);
?>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
</head>
<body>
Source:
<input type="textbox" name= "tag" id="tags">
<select id="movieImdbId" name="movieImdbId[]" multiple="multiple" width="200px" size="10px" style=display:none;>
</select>
<script type="text/javascript">
$(document).ready(function () {
$("#tags").autocomplete({
source: "actorsauto.php",
minLength: 2,
select: function (event, ui){
$("#tags").change(function () {
var selectedVal = $(this).val(); //this will be your selected value from autocomplete
// Here goes your ajax call.
$.post("actions.php", {q: selectedVal}, function (response){
// response variable above will contain the option tags. Simply put in the dropdown.
$("#movieImdbId").html(response).show();
});
});
}
});
});
</script>
</body>
</html>
这是actions.php代码:
如果有人能帮我修理,我真的很感激
谢谢。你可以通过邮局打电话
$.post("actions.php")
但是检查GET变量
if(isset($_GET['q']) && !empty($_GET['q']))
所以我猜你的php脚本提供了一个空字符串。
将响应打印到console,然后查看是否有结果。谢谢,但更改get to POST并没有改变任何内容。。我不认为这是问题所在:您是否检查了php脚本是否提供了结果?我修复了它:只需将FETCH_OBJ替换为FETCH_ASSOC即可:
if(isset($_GET['q']) && !empty($_GET['q']))