== A demo of an Ajax style application == The following code demonstrates how to write a simple Ajax (Asynchronous JavaScript and XML) application. It uses the [[http://jsolait.net|Jsolait]] library to do the hard work of dealing with the XMLHttp object, and Quixote's xmlrpc support to expose methods from the server. All of the code is in a single module - this isn't an example of good style, although it does demonstrate how a full Quixote application can be built as a single module... {{{#!python from quixote.directory import Directory from quixote.util import StaticDirectory, xmlrpc from quixote import get_request import xmlrpclib from quixote.publish import Publisher def create_publisher(): return Publisher(MyRoot()) class RPC(object): def __call__(self, meth, args): meth = getattr(self, meth, None) if meth: return meth(*args) def echo(self, *args): return args def get_time(self): import time now = time.gmtime(time.time()) return xmlrpclib.DateTime(now) RPC = RPC() JS = """\ var xmlrpc = importModule("xmlrpc"); var svc = new xmlrpc.ServiceProxy("http://localhost:8080/rpc", ["get_time"]); function update() { var time = svc.get_time(); var txt = document.createTextNode(time); var sp = document.getElementById("time"); sp.replaceChild(txt, sp.firstChild); } """ TEMPLATE = """\
Current Time is: 0000