我的搜索词作为空字符串传递给我的处理程序。这是组件:
html表单:
<form class="navbar-search" action="/search">
<input type="text" class="search-query span3 ajax-typeahead" placeholder="Search" data-link="/typeahead" name="searchQuery" autocomplete="off" />
<button class="btn btn-primary" style="margin-top: 0px;" type="submit">
<i class="icon-search icon-white"></i>
</button>
</form>
用于预先输入的 jquery:
<script type="text/javascript">
$(document).ready(function() {
$('.ajax-typeahead').typeahead({
source: function(query, process) {
return $.ajax({
url: $(this)[0].$element[0].dataset.link,
type: 'get',
data: {query: query},
dataType: 'json',
success: function(json) {
return typeof json.options == 'undefined' ? false : process(json.options);
}
});
}
});
});
</script>
python webapp2处理程序:
class SearchHandler(webapp2.RequestHandler):
def get(self, searchQuery):
self.response.out.write('Term: %s' % searchQuery)
app = webapp2.WSGIApplication([('/search(.*)', SearchHandler)],
debug=True)
结果:
我似乎找不到问题,感谢任何帮助