let's say I type for example "j" and I should see autocomplete like for example John with more suggestions below input tag, but I don't. In my console I get ["John", "Jane"]
, no errors.
test.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
<div id="aa">
<input class="typeahead" type="text" placeholder="names">
</div>
<script src="../static/jquery-1.11.3.min.js"></script>
<script src="../static/typeahead.bundle.js"></script>
<script>
$('#aa .typeahead').typeahead(null, {
source: function (query, process) {
$.ajax({
url: '/test/',
type: 'GET',
contentType: "application/json; charset=utf-8",
data: {'query': query},
success: function(data) {
console.log(data.options);
process(data.options);
}
});
}
});
</script>
</body>
</html>
app.py
from flask import Flask, render_template, url_for, jsonify, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('test.html')
@app.route('/test/')
def test():
print request.args.get('query')
return jsonify(options=["John","Jane"])
if __name__ == '__main__':
app.run(debug = True)