import time

import cherrypy

page = \
"""<html>
    <head>
    <script type="text/javascript">
        function update() {
            var diva = document.getElementById('diva');
            var divb = document.getElementById('divb');
            
            
            var req1 = new XMLHttpRequest();
            req1.onreadystatechange = function () {
                if(req1.readyState == 4 && req1.status == 200) {
                    diva.innerHTML = req1.responseText;
                }
            };
            
            var url = "/load_a";
            req1.open("GET", url, true);
            req1.send(null);

            var req2 = new XMLHttpRequest();
            req2.onreadystatechange = function () {
                if(req2.readyState == 4 && req2.status == 200) {
                    divb.innerHTML = req2.responseText;
                }
            };
            
            var url = "/load_b";
            req2.open("GET", url, true);
            req2.send(null);
        }
    </script>
    </head>
    <body>
    <div id="diva"></div>
    <div id="divb"></div>
    <a href="javascript:update()">Update</a>
    </body>
</html>
"""

class Test(object):
    @cherrypy.expose
    def index(self):
        return page

    @cherrypy.expose
    def load_a(self):
        time.sleep(2)
        return "A's time: %s" % time.ctime()

    @cherrypy.expose
    def load_b(self):
        return "B's time: %s" % time.ctime()

cherrypy.tree.mount(Test())
cherrypy.config.update({'log_debug_info_filter.on':False})
cherrypy.server.start()

