I use the Django web framework to create a database, create pages, etc.
jQueryUI / side of JavaScript code
I want to use jQueryUI autocomplete widget , since my data set will contain about 1000 records that I wanted to query in the database. From the link above, he claims that you can simply provide a URL that returns JSON data:
Autocomplete can be configured to work with various data sources by simply specifying the source option. Data source can be:
* an Array with local data * a String, specifying a URL * a Callback
I accepted the default example on a website that runs on my system.
However, if I change the following:
$( "#tags" ).autocomplete({ source: availableTags, });
to
$( "#tags" ).autocomplete({ source: "/search/",
the autocomplete function does not work at all.
I tried to make url really return an error (to make sure that it uses it) and insert the full url http://localhost:8000/search/ , nothing works.
Django piece of code
In url.py
... (r'^search/$', 'search'), ...
In views.py
from django.http import HttpRequest, HttpResponse from django.utils import simplejson ... def search(request): HttpResponse(simplejson.dumps(["hello", "world"]))
There should be something wrong in my code, and I would really appreciate any help you can offer :)
SOLUTION DECISIONS:
Thanks to @Thierry, I realized that there was no return before, they added that now I look like this:
def search(request): output = ["hello", "world"] return HttpResponse(simplejson.dumps(output))
And it really works!
(These seem to be really small bugs that spend most of my time, grrr)