JQuery автозаполнение в колбе
Не удается заставить виджет автозаполнения jQuery работать с платформой Flask. (http://jqueryui.com/autocomplete/#remote вот пример)
Вmanage.py Я получил следующее:
@app.route('/autocomplete', methods=['GET'])
def autocomplete():
results = []
search = request.args.get('autocomplete')
for mv in db_session.query(Movie.title).filter(Movie.title.like('%' + str(search) + '%')).all():
results.append(mv[0])
return jsonify(json_list=results)
мойindex.html файл:
<head>
...
<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet"></link>
<script src="../static/js/jquery.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script>
<script type="text/javascript">
$(function() {
$.ajax({
url: '{{ url_for("autocomplete") }}'
}).done(function (data) {
$('#autocomplete').autocomplete({
source: data.json_list,
minLength: 2
});
});
});
</script>
...
</head>
<body>
...
<div>
<input name="autocomplete" type="text" id="autocomplete" class="form-control input-lg"/>
</div>
...
</body>
Похоже, что инструменты разработчика в Firefox не возвращают никаких ошибок. Терминал возвращает следующее:
«GET / автозаполнение HTTP / 1.1» 200 -
«GET / HTTP / 1.1» 200 -
«GET /static/css/bootstrap.css HTTP / 1.1» 304 -
«GET /static/js/jquery.js HTTP / 1.1» 304 -
Виджет просто не работает. Так как я не знаю много о jQuery, я не могу понять, что является причиной проблемы. Кто-нибудь может мне помочь, пожалуйста?