On May 15, 12:14 pm, newbie <mara.ku...@gmail.com> wrote: > Hi, > > i'm new to both ajax and django. Can some1 explain me how to > write a view function for an ajax functionality in a template. For > example, I've registered a ajax event in a template and wanted to send > some information to a function in a view which inturn sends its > response. How do i do that. > > I wanted to create a form which two select boxes. Based on the input > of the first select box, I would like to throw in the options for the > select box. I can write a onchange function for the first select box > but how do i send that information to a function in a view which would > inturn send the options of the second select box. > > One more complexity i came up with here is, in django forms are > created by declaring classes. so when i create a select box by calling > something like box = forms.ChoiceField > (choices=options,required=False), how do i change the choices > attribute here. > > Thanks, > Nazgi
An AJAX view is exactly the same as a normal view in Django - in other words, you need an entry in urls.py, which routes to a view, which returns a response. The only difference is that the response is usually something like JSON rather than HTML. So in your case you want your javascript to call a URL which accepts a parameter for your selected value, and returns a JSON list of corresponding values for the second select box. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---