我正在尝试在 cakephp 3.x 中执行实时搜索,到目前为止,我可以通过静态定义脚本标记内的数据来实现它,我希望从存储所有内容的 MySql 数据库中检索数据. 下面是我在模板文件夹中使用的脚本标签。
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!-- Javascript -->
<script>
$(function() {
var results = [
"ActionScript",
"Boostrap",
"C",
"C++",
];
$( "#automplete-1" ).autocomplete({
source: results
});
});
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<html>
<body>
<!-- HTML -->
<div class = "ui-widget">
<?php foreach($data as $row)
{
echo $row->name;
}?>
<p>Type "a" or "s"</p>
<label for = "automplete-1">Tags: </label>
<input id = "automplete-1">
</div>
</body>
</html>