Hi everybody,

I would like to share a little test to keep working qooxdoo and cherrypy
with AJAX communications.
You need to install Python 2.7, cherrypy and jinja2 template system.

Start installing an empty qooxdoo application with:

python create-application.py --name my_ajax_test

then write a python script with the following source code into my_ajax_test
directory:

8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<-------

import cherrypy
from jinja2 import Environment, FileSystemLoader
import os.path
import json

QXDEBUG = True

if QXDEBUG:
    qxpath = 'source'
else:
    qxpath = 'build'

current_dir = os.path.join( os.path.dirname(os.path.abspath(__file__)),
qxpath)
env = Environment(loader=FileSystemLoader(qxpath))

conf = {
    'global' : {
        'server.socket_port' : 8080,
        },
    '/' : {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': current_dir + '/'
        }
    }

if QXDEBUG:
    conf['/source'] = {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': current_dir
        }

class Root:
    @cherrypy.expose
    def index(self):
        tmpl = env.get_template('index.html')
        return tmpl.render()

    @cherrypy.expose
    def ajax_qx(self, title):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps(dict(title="%s from cherrypy" % (title)))

cherrypy.quickstart(Root(), config=conf)

8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<-------

and modify the source of Application.js file in this way:

8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<-------

      // Add an event listener
      button1.addListener("execute", function(e) {
        // Instantiate request
        var req = new qx.io.request.Xhr("ajax_qx", "POST");
          req.setRequestData({"title": "Hello"});

          req.addListener("success", function(e) {
          var req = e.getTarget();
          var response = req.getResponse();
          alert(response['title'] );
        }, this);
      req.send();

8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<-------

now start the cherrypy server with:

python cherrypy_server.py

and go to page:

http://localhost:8080/

Press the button and you should see: "Hello from cherrypy"

This is all.

P.S. the jinja2 template system is an overkill, but can be useful so I
leaved it.
P.P.S. If you use Python versions before 2.7 you need SimpleJson instead
json.

Best Regards
Claudio Driussi






--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/qooxdo-AJAX-cherrypy-tp7585805.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to