Thang Nguyen schrieb:
> Thanks for your email.   Still could not get it to work.  I probably
> do not understand well how this thing (jquery/turbogear/cache)
> supposed to work.  I will dig into it further, any additional
> suggestion is greatly appreciated.  -tpn
> 
> My answers to your questions:
> ======================
> 
> (1)  There is no particular reason to use local import, I need to clean up 
> that.
> 
> (2)  The call (load) works fine, as shown in the output, but the
> replacement of "timetest" does not happen when "get time" is clicked.
> I also modified the code to add a random number to the query such as
> load("/time?sid=" + Math.random())... but does not help though.
> 
> Below are the sample code and the output (btw, I tried this on both
> Firefox and IE, no difference).  Also I did not see any difference
> between using $('timetest') versus $('#timetest')
> 
> template:
> =======
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>                       
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";
>       xmlns:py="http://genshi.edgewall.org/";
>       xmlns:xi="http://www.w3.org/2001/XInclude";>
> 
>   <xi:include href="master.html" />
> 
> <head>
>   <meta content="text/html; charset=UTF-8" http-equiv="content-type"
> py:replace="''"/>
>   <title>Learning TurboGears 2.0: Quick guide to the Quickstart pages.</title>
>   <script type="text/javascript">
>      $(document).ready(function(){
>        $('a').click(function(event){
>            $('#timetest').load("/time?sid=" + Math.random())
>        });
>      });
> 
>    </script>
> </head>
> 
> <body>
>   <div id="timelink"><a href = "#">get time</a></div>
>   <div id="timetest" py:replace="now"></div>
> </body>
> </html>
> 
> 
> Controller (root.py)
> ==============
>    @expose('helloworld.templates.about')
>     def about(self, **kw):
>         jquery_js.inject()
>         return dict(now=time.ctime())
> 
>     @expose()
>     def time(self, sid):
>         print "time is called ...sid=%s" % sid
>         return dict(now=time.ctime())
> 
> 
> Output (server console):
> =================
> serving on 0.0.0.0:8080 view at http://127.0.0.1:8080
> time is called ...sid=0.7600414370879561
> time is called ...sid=0.08766271084959143
> time is called ...sid=0.9154010756223916
> time is called ...sid=0.13931412162353551
> time is called ...sid=0.9629765981657245
> time is called ...sid=0.19117089588204772
> time is called ...sid=0.6440978896256766
> time is called ...sid=0.550432448440006
> time is called ...sid=0.9023927250869724
> time is called ...sid=0.1985474145942756
> time is called ...sid=0.14242761973297957
> time is called ...sid=0.5346612822522109
> time is called ...sid=0.6367426755820135
> 
> 
> tpn
> 
> 
> On Mon, Dec 14, 2009 at 12:27 PM, Diez B. Roggisch <[email protected]> wrote:
>> Hi,
>>
>>
>>> I followed your suggestion and was able to inect jquery_js to my
>>> controller.  However, I am running into a problem.  Below is the
>>> sample code.  I expect to see the time (id=timetest)  to be updated
>>> everytime I click on "get time" link; however, it does not.   Hope you
>>> can shed a light on it.   Thanks much in advance. -tpn
>>>
>>> From my controller  (root.py):
>>> =====================
>>>
>>>  @expose('helloworld.templates.about')
>>>     def about(self, **kw):
>>>         import time
>>>         jquery_js.inject()
>>>         return dict(now=time.ctime())
>>>
>>>     @expose()
>>>     def time(self):
>>>         import time
>>>         return dict(now=time.ctime())
>> Any reason you don't import time *once* on top of the module? It doesn't
>> change the semantics, but local imports should only be used when there
>> is good reason - circular dependencies or lazy loading.
>>
>>
>>>
>>> From my template:
>>> ==============
>>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>>>                       
>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>>> <html xmlns="http://www.w3.org/1999/xhtml";
>>>       xmlns:py="http://genshi.edgewall.org/";
>>>       xmlns:xi="http://www.w3.org/2001/XInclude";>
>>>
>>>   <xi:include href="master.html" />
>>>
>>> <head>
>>>   <meta content="text/html; charset=UTF-8" http-equiv="content-type"
>>> py:replace="''"/>
>>>   <title>Learning TurboGears 2.0: Quick guide to the Quickstart 
>>> pages.</title>
>>>   <script type="text/javascript">
>>>      $(document).ready(function(){
>>>        $('a').click(function(event){
>>>            $('#timetest').load("/time")
>>>        });
>>>      });
>>>
>>>    </script>
>>> </head>
>>>
>>> <body>
>>>   <div id="timelink"><a href = "#">get time</a></div>
>>>   <div id="timetest" py:replace="now"></div>

This looks as if you *replace* the div with whatever now contains. So 
there is no div anymore, and then of course the jquery-statement 
referring to the id of the div wont' have anything to work on.

Make that "py:content" instead, and you are good to go.

Diez

--

You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.


Reply via email to