Ian Bicking: the old part of his blog

My First Ajax App

Well, it took a while, but I finally finished my first experiment with Ajax (aka Asynchronous Javascript and XML; i.e., DHTML revisited). It actually doesn't use XML, but I guess it uses XMLHttpRequest, so that's good enough.

Sadly I cannot demo it for you all, but you can run it on your own with Paste; it's at http://svn.pythonpaste.org/Paste/trunk/examples/console -- it gives you an interface similar to the interactive interpreter in Python (obviously not secure for the public web!). When you enter a command, it sends it to the server (as a URL-encode POST request at the moment), and the server returns any output (including the repr of any expression, the way the interactive interpreter does). I used code from doctest as a model for evalcontext, which implements the actual interpreter part. Everything gets interpreted in the server process, so potentially it's a debugging tool. I can imagine lots of ways to improve it for debugging -- things like HTML object inspectors -- but this is just a minimal experiment at this point. Or other similar tools, like something similar to tail that shows an ongoing list of log messages. (Paste first needs a logging system, though -- based on logging of course, but made more convenient)

In theory you could even hook up pdb to this kind of system and debug exceptions. That would be neat. Not that I actually use pdb that often, but I feel like I should. Right now post-mortem debugging is generally more useful to me, and with good post-mortem debugging the interactive work isn't as hard. I still need to add cgitb-like capturing of local variables. But I can imagine an entirely different error middleware (different than this) that implements the debugger. Parallel development of these things is part of what I hope to see from WSGI.

Thinking about it, it doesn't even seem that hard. You catch an execption. You get sys.exc_info(), which contains all the frames from the exception, and thus contains all the local variables. You show a traceback. You have something like this interactive console, but you also let the user select a frame from the traceback, so that their statements will be executed in that scope. And there you have a pretty neat little debugging environment. Fun. But... must... not... get... distracted...

I used Javascript O Lait for the Javascript. I tried using JSON-RPC (via ServerProxy and JSONComponent), but it was too slow for some reason. I'll figure that why later. So in the end I just used urllib, which is a fairly thin wrapper around XMLHttpRequest. I've looked at Dojo, which seems simple but doesn't seem to have any useable documentation and the download is huge and confusing. I looked at Sarissa, but it's mostly about XML, and XML is the least interesting part of Ajax to me. I looked at Sajax, but it's a little too clever with the server-side stuff for me. I want to develop the server-side integration myself, in whatever way makes best sense for the framework. But it probably deserves a bit more attention; it's the next closest in scope to what I'm interested in.

Dang, that's a lot of links. Well, there's my link dump for ya'.

Created 07 May '05

Comments:

http://deadbeefbabe.org/shell seems to be the same thing implemented with nevow's livepage. very cool!

# anonymous

Same stuff here:

http://john.thetrotter.net/cherryshell.html

Lorenzo

# Lorenzo

Sigh, the site is down now. Well, I looked at it before, and it looks quite cool, integrating a richer shell than the one I dug out of doctest into the browser (PyShell...?)

# Ian Bicking

cherryshell still there now version 0.2 ;) http://john.thetrotter.net

Anyway site goes down sometimes when i am doing changes. But is will come back :)

Also there is pyroshell (remote pyshell with pyro) not really usefull but proof of concept

site goes up and down because I do changes.

cherryshell 0.2 is quirky but works and is cool (lol me prejudiced) it quirk thought.

I need to make gui class for javascript. Working on that then will release 0.3

# nopa90

I think (no benchmarking) that jsonrpc with jsolait is quicker then xmlrpc.

I was using it on project that fall through :(. To get results from a db and give them back to user.

approx size of db 10,000 and results where like 300. It could fetch them in less then 1 second, plus page do not have to be regened.

When I use xmlrpc it was slower 1.5 sec.

I have crappy virtual server.

I was thinking of making a debugger, with same idea, but the client browser would have to poll the server. (I do not think with javascript there is a way to send result to client, without client initiating the request).

I do not understand why in your case jsonrpc slow

# nopa90

Concerning, "I do not think with javascript there is a way to send result to client, without client initiating the request," Nevow's LivePage addresses this concern.

# Shannon -jj Behrens

A Oracle form like AJAX Data-driven web sample application, http://rhae.dunco.com.my/examples/lppbap/jsp/ . This is a combination of JSP/Servlet/JavaBean driven backend and AJAX/JSP web form as front end. All form, backend, AJAX handling of this application was generated by Motionk AjaxApp Rapid Builder, an ASP version is hosted @ http://rhae.dunco.com.my/tools/LoginFormServlet . The generated application is fully working with all the database handling including add new, update, delete, select record etc.

A PHP AJAX shopping cart, http://www.smartborneo.com/h/home.php

# K.Y. Chee