Ok, I will try this way.

Thank a lot!


On Feb 5, 11:50 pm, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On Feb 5, 12:19 pm, min <inuyasha...@gmail.com> wrote:
>
>
>
>
>
> > Hi, everyone.
>
> > I'm learing Django now. Currently, I have a problem with Django and
> > jQuery. The detail is that:
>
> > Firstly, I have a form in the forms.py:
>
> > class TestForm(forms.Form):
> >     name = forms.CharField( max_length=30 )
>
> > Then, in the views.py:
>
> > def Test_page(request):
> >     form = TestForm()
> >     result= ''
> >     if request.GET.has_key('name'):
> >         query = request.GET['name'].strip()
> >         if query:
> >             form = TestForm({'name': query})
> >             result= 'aaaa'
> >     variables = RequestContext(request, {
> >         'form': form,
> >         'result': result
> >          })
> >     return render_to_response('Test.html', variables)
>
> > I'd like to use the 'result' parameter in the jQuery script in the
> > Test.html, when the user inputs some characters in the name field and
> > click the sumbit button.
>
> > The problem is that, when I use  var y = "{{result}}" by jQuery
> > function, the real value in the y is NOT 'aaaa' which I defined in the
> > views.py. By contrast, The real value for y is {{result}}.
>
> > However, if I only use the original javascript script in the Test.html
> > by var x ="{{result}}", the real vaule in the x is 'aaaa'.
>
> > Do you know how to use the 'result' parameter in the jQuery function?
>
> > thank you very much!
>
> The external jQuery script doesn't go through Django, so obviously the
> template variables aren't parsed. As you have discovered, you can put
> javascript in the template so that it is parsed. So you already have
> the answer to your question: use a small script within your template,
> which sets the values you need from the context and makes them
> available as global javascript variables. Then your external jQuery
> script will be able to access the global JS variables which will have
> the correct values.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to