Zeynel
Zeynel

Reputation: 13515

How do implement jQuery autocomplete in Google App Engine with Python?

I found several sources discussing this problem, (this one seems the simplest but it is for PHP). I will be using an existing search form and I created AutocompleteResponse handler to handle the request. I don't understand from the documentation if it is required that the data sent will be in json format or an array of string is ok. I am not sure about what information to send either. I created a new model with search history

class Search(db.Model):
    owner = db.UserProperty()
    date= db.DateTimeProperty(auto_now_add=True)
    query = db.StringListProperty()

and I want to send the relevant query suggestions to autocomplete. Any help to examples whether in documentation or otherwise is welcome. Thanks.

Update

I put this just before the closing </body>

<script>
$('#search_form').autocomplete({
            source: "http://ting-1.appspot.com/autocomp",
            minLength: 2});
</script>            

in my Autocomp handler I put

data = json.dumps("abc, def")

I naively think that data will be passed to jquery autocomplete plug in. But nothing is happenning. What am I doing wrong?

Upvotes: 2

Views: 628

Answers (1)

Kevin P
Kevin P

Reputation: 1655

Just tried this and it worked:

    data = ['cat','dog','bird', 'wolf']
    data = json.dumps(data)         
    self.response.out.write(data)

Upvotes: 2

Related Questions