I’m in position where the autocomplete triggers a http request using get and q attribute. I managed to process the q input and produced a result list.
then I serialized the list into json and send it back, but somehow I can’t see the result.
This is my view code:
def autocomplete_company(request):
if request.is_ajax():
q = request.GET.get('q', '')
companies = Company.objects.filter(name__icontains = q ).order_by('name')[:10]
results = companies.values_list('name', flat=True)
data = simplejson.dumps([unicode(r) for r in results])
else:
data = 'fail'
return HttpResponse(data, mimetype="application/json")
AJAX:
$(function(){
$("#search_type").autocomplete("/company/autocomplete/",{
minChars: 2
});
});
any thoughts?
You forgot to pass the querystring ‘q’ in your request