【发布时间】:2022-01-19 20:05:52
【问题描述】:
我有这个输入,我想用下面的脚本自动完成。 url 返回一个字符串列表。 当我输入时,数据会显示在控制台中,但不会弹出自动完成窗口。
可能出了什么问题?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<input type="text" class="form-control my-input" name="from" id="from">
<script>
$(document).ready(function () {
$("#from").keyup(function (string) {
$.ajax({
type: "GET",
url: "http://127.0.0.1:5000/complete?station=" + $(this).val(),
success: function (data) {
$("#from").autocomplete({
source: data
});
console.log(data)
}
});
});
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript html jquery ajax