我在表单上使用 jquery 自动完成功能,并尝试对提交表单条目时选择的内容进行简单回显,以验证我的数据是否被正确读取。我收到以下消息:
注意:第 4 行 C:\xampp\htdocs\New\search.php 中的数组到字符串转换
Search.php 内容:
<?php
$dest_name = $_GET["dest_name"];
echo ["dest_name"];
?>
Html 内容:
<body>
<form method="GET" action="search.php">
<div>
<input type="text" id ="destination" name="dest_name"/>
</div>
</form
</body>
自动完成脚本
var destinations = [
{value: "49 Degrees North Ski Area",label: "49 Degrees North Ski Area",id: "1"},
{value: "Afton Alps",label: "Afton Alps",id: "2"},
{value: "Al Quaal Recreation Ski Area",label: "Al Quaal Recreation Ski Area",id: "3"},
{value: "Alpental",label: "Alpental",id: "4"},
{value: "Alpine Meadows",label: "Alpine Meadows",id: "5"},
];
$(document).ready(function() {
$("#destination").autocomplete({
source: destinations,
focus: function(event, ui) {
$("#destination").val(ui.item.label);
return false;
},
select: function(event, ui) {
$("#destination").val(ui.item.label);
$("#dest_id").val(ui.item.id);
return false;
}
});
$('#button').click(function() {
alert($("#dest_id").val());
});
});