How do i use jquery autocomplete? will you please help me ? thank you
UPDATE: I have written following view. Which works just fine without ajax. Now I want to integrate with ajax. I tired alot. But found no luck. I need your help. Thank you guys
UPDATED views.py
def search(request):
errors = []
if 'q' in request.GET:
q = request.GET['q']
if not q:
errors.append('Enter a search term.')
else:
categories = UserProfile.objects.filter(user=request.user)[0]
languages = categories.language.all()
movies = Movie.objects.filter(title__istartswith=q,language__in=languages)
results = [ x.title for x in movies ]
json = simplejson.dumps(results)
return HttpResponse(json, mimetype="application/json")
my form
<form action="/search/" method="get">
<input type="text" name="q" id ="q">
<input type="submit" value="Search">
</form>
UPDATE3: When I use following ajax function. It worked. Its displaying the data in terminal. But the problem is that its not showing list of movies in input field.
d
my ajax
<script>
$(document).ready(function() {
$("#q").autocomplete("/search/");
});
</script>
UPDATE 4: I’ve just changed the code. Now its displaying the contents in one line. Here is screenshot.

UPDATE 5: When I use this return HttpResponse(json, mimetype="plan/text") it worked. but the problem is same (all contents in one line). If i use return HttpResponse(json, mimetype="application/json") It does not work.
You are using ‘q’ as the get string, but the jquery autocomplete widget expects it to be called ‘term’. You need to make the following change at the start of your view:
Edit: The next part of the answer was added before the OP updated their question and json encoded the results.
You can’t just return a queryset of movies — it has to be in a format that the autocomplete widget can understand. The easiest thing is to return a list of names (the same as in example you tried with programming languages. The end of your view should look something like this:
See how you get on with that, and leave a comment if you’re still having trouble.