On Monday 01 October 2007 04:49:17 delsur wrote:
> hi,
>
> I am trying to make an example in order to understand how to work with
> ajax and TG. I am doing this:
>
> controllers.py :
>
> class AjaxController:
> @expose(format='json')
> def runcommand(self):
> t = datetime.datetime.now()
> tiempo = time.mktime(t.timetuple())
> return dict(ti=tiempo)
>
> class Root(controllers.RootController):
> @expose(template="agendatg.templates.runcommand")
> def index(self):
> .........
> .........
>
> ajax = AjaxController()
>
> runcommand.kid
>
> .... <head>
> <script src="${tg.tg_js}/MochiKit.js"/>
> <script type="text/javascript" src="/static/javascript/
> runcommand.js"></script>
> </head>
> <body>
> ....
> <script>setInterval('async_command_output("http://localhost:8080",
> 100000)');</script>
> </body>
>
> runcommand.js:
>
> function async_command_output(url){
> d = doSimpleXMLHttpRequest(url+"/ajax/runcommand");
> d.addCallback(display_command_output);
> }
>
> function display_command_output(xmlhttp)
> {
> var o = evalJSONRequest(xmlhttp);
> document.getElementById("command_output").innerHTML =
> '<pre>'+o.data
> +'</pre>';
> }
>
> I could make these things because Chris helped me in my previous post
> about datagrid autorefresh :)
>
> But I couldn't have the example working, I have an "undefined" result
> in my page. I tried to debug with firebug , and it seems that I have
> an error in the way which I calling the command ajax/runcommand ,
> because the object Deferred has unfired status , but actually I don't
> know
Does the request come through to the server? Then your problem is not in ith
doSimple..., but in the display_command_output.
And there you have an error for sure: your controller returns
{'ti' : 123123}
whereas you access it as if it was
{'data' : 21312}
which obviously is undefined!
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
-~----------~----~----~----~------~----~------~--~---