I have this input which I want autocomplete with the script bellow.
The url returns a list of strings.
When I type, the data are shown in console however the autocomplete window does not pop up.
What might be wrong?
<!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>
2
Answers
This did it:
You should add
jQuery-ui.min.css
,jquery.min.js
andjquery-ui.min.js
files to the project. The following application, which I developed using mock data, works successfully. I called thegetList()
method in the error field to simulate the response from the server.Application test image is available below:
Application source code is available below: