On 3/9/07, johnny <[EMAIL PROTECTED]> wrote:
>
> I am new to python and javaScript, I have created a funtion that
> return the tags via ajax.  I tried to replicate the php example.  But
> it's not working.  I doesn't return any tags back to my html page via
> ajax.  I need some help.  I am using jQuery autocomplete plugin from
> here: 
> http://just-tech.blogspot.com/2006/12/jquery-tweaking-auto-complete-plugin.html.
> Here is my function in view:
>
> def tag_autocomplete(request):
> #    $q = $_GET['q'];
> #    foreach($countries as $country) {
> #    if(eregi("^".$q, $country)) {
> #        echo $country."\r\n";
> #    }
>
>     s = request.GET.get('q', '')
>     current_tags = list(Tag.objects.all())
>     for tag in current_tags:
>         if (search (s.lower(), tag.normalized_tag)):
>             print "%s" % (tag.normalized_tag)
>
For django, just print won't return the result, but print output in
the console(if you are using develping server), you should return a
HttpResponse() object, and the good format of the returned data is
json, so there is a example from your code:

    from django.utils import simplejson

    s = request.GET.get('q', '')
    #current_tags = list(Tag.objects.all())
    result = []
    for tag in Tag.objects.filter(name=s):
        #if (search (s.lower(), tag.normalized_tag)):
        #    print "%s" % (tag.normalized_tag)
        result.append(tag.normalized_tag)
    return HttpResponse(simplejson.dumps(result))

If you are using Firefox and installed Firebug plugin, you can see the
response message.


-- 
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to