Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Ajax convenience.

Project description


AJAX convenience.

This package bundles required resources for the use of bdajax inside a bfg or zope application. It does NOT include the required server implementations.

bdajax provides some JavaScript helper functions and a simple dispatcher system which is driven by attributes. These attributes are defined in a XML namespace extension, placed in your XHTML markup.

You can basically control 3 behaviors with the supported attributes:

  • Call functions
  • Trigger events
  • Perform actions

Each behavior is bound to a JavaScript event itself.


For those who know KSS (Kinetic Style Sheets) and TAL (Tag Attribute Language); The syntax reminds of TAL - attributes are interpreted by JS instead of a TAL interpreter - while the functionality is inspired by KSS.

The main paradigm and at the same time the main difference to KSS is the use of an event/listener model, what makes it possible to listen to, and trigger events on ajaxified DOM components.

Consider a navtree as example; the idea is to trigger an event when a navigation item gets clicked, and listen to this event on all DOM elements which wants to get notified if server context changes (what is indicated by the thrown event).

This makes it possible to have completely decoupled “sub-applications” knowing nothing but an event contract from each other.


You can define the following attributes in your markup:

  • ajax:bind=”evt1 evt2”
    Indicate bdajax behavior on DOM element and the event(s) triggering it/them.
  • ajax:call=”function1:selector1 function2:selector2”
    Call function(s). The function gets passed a jQuery iterator of selector and a target object. Target object provides url and params.
  • ajax:event=”evt1:sel1 evt2:sel2”
    Trigger event(s) on selector. The triggered event gets the target as additional parameter on event.ajaxtarget.
  • ajax:action=”name1:selector1:mode1 name2:selector2:mode2”
    Perform AJAX action(s) on selector with mode. selector points the target DOM element while mode defines how to modify the DOM tree. Possible mode values are inner and replace.
  • ajax:target=””
    AJAX target definition. Consists out of target context URL and a query string used for requests on the target context. ajax:target is mandatory when ajax:event is defined, and optional when ajax:action is defined (depends if event is triggered by bdajax or browser event). See below to get a clue what i am talking about.

Provide dependencies on server

This package already includes resource configuration for Zope and bfg. This is done due to ZCML. Please include one of the following ZCML include statements depending on your platform.

<include package="bdajax" file="bfg.zcml" />

for use in bfg, and

<include package="bdajax" file="zope.zcml" />

for use in Zope.

The expected ajacaction view is not provided. Thats intended to be a custom implementation. See ‘Perform actions’ below.

Load dependencies in markup

You have to load dependent JavaScripts and CSS in HTML header

<script src=""></script>
<script src=""></script>
<script src=""></script>
<link href=""
      rel="stylesheet" type="text/css" media="screen" />

You have to make sure that the contents of are rendered in your markup as well.

Define namespace

In order to keep your XHTML valid when using the XML namespace extension you have to define this namespace in your XHTML document

<html xmlns=""

Event binding

Indicate bdajax behavior on DOM element

<a href=""
   ajax:bind="keydown click">

Binds this element to events keydown and click.

Calling functions

Provide the function to be called in your JavaScript

somefunc = function(iter, target) {
    // do something

Bind call behavior to DOM element

<a href=""

When the link gets clicked, somefunction is called which gets passed an iterator, in this case jQuery(‘.someclass’), and a target object, containing url and params if ajax:target is set.

Trigger events

Bind event behavior to DOM element

<a href=""

This causes the contextchanged event to be triggered on all DOM elements defining contextsensitiv css class. The extra attribute ajaxtarget gets written to the event before it is triggered, containing definitions from ajax:target.

Perform actions

An action performs a JSON request to the server and modifies the DOM tree as defined.

bjadax expects a view named ajaxaction on server. This view gets called on target url with target query parameters. 3 additional arguments are passed:

  • bdajax.action - the name of the action
  • bdajax.selector - the selector must be added to response
  • bdajax.mode - the manipulation mode. Either inner or replace

The view is responsible for rendering the requested resource and return a JSON response in this format:

    mode: 'inner',            // the passed mode
    selector: '#someid',      // the passed selector
    payload: '<div>...</div>' // the rendered action

Bind an action which gets triggered directly

<a href=""

When this link is clicked, the DOM element with id fubar gets replaced with results of action renderfubar. Request context and request params are taken from ajax:target definition.

Bind an action which acts as event listener. Consider section ‘Trigger events’. The event triggered there indicates that context has changed to target with params. Now we want to react on this and perform some action

<div id="content"

Note, if you bind actions as event listeners, there’s no need to define a target since it is passed along with the event.

Multiple behaviors

Bind multiple behaviors to one DOM element

<a href=""

In this example, when the link gets clicked, function somefunc is called, event contextchanged is triggered and action rendersomething is performed.

JavaScript helpers

Messages, Infos, Warnings and Errors

bdajax provides displaying application messages in a jQuery tools overlay. bdajax.message displays a message as is, while, bda.warning and bda.error decorates the message with the appropriate icon.

bdajax.message('I am an application Message');

URL Operations

You can parse hyperlinks for base URL or request parameters


results in




results in

{ param: 'value' }

You can do both at once by calling parsetarget


This result in

    url: '',
    params: { param: 'value' }

XMLHTTPRequest convenience

bdajax provides the function request as convenience for XMLHTTPRequests. By default it sends requests of type html and displays a bdajax.error message if request fails.

    success: function(data) {
        // do something with data.
    url: 'foo',
    params: {
        a: 'a',
        b: 'b'
    type: 'json',
    error: function() {
        bdajax.error('Request failed');

Given url might contain a query string. The query gets parsed and written to request parameters. If same request parameter is defined in URL query AND params object, latter one rules.


success - Callback if request is successful.

url - Request url as string.

params - Query parameters for request as Object (optional).

type - xml, json, script, or html (optional).

error - Callback if request fails (optional).

Perform action manually

Sometimes you want to perform actions manually. Use bdajax.action for this.

var target = bdajax.parsetarget('');
    name: 'content',
    selector: '#content',
    mode: 'inner',
    url: target.url,
    params: target.params


name - Action name

selector - result selector

mode - action mode

url - target url

params - query params

Trigger events manually

Sometimes you want to trigger an event manually. Since bdajax expects the attribute ajaxtarget on the received event we provide a convenience.

var url = '';
bdajax.trigger('contextchanged', '.contextsensitiv', url)

3rd Party Javascript

When writing applications, you might have your own set of custom javascrips where some actions has to be bound in your markup. Therefor the object binders exist on bdajax. Just hook your binding callback to this object and it will be called every time bdajax hooks some markup.

mybinder = function (context) {
    jQuery('mysel').bind('click', function() { ... });
bdajax.binders.mybinder = mybinder;


bdajax is tested in:

  • Firefox 3.5
  • IE 7
  • to be continued…




  • make it work [rnix]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bdajax, version 1.0b1
Filename, size File type Python version Upload date Hashes
Filename, size bdajax-1.0b1.tar.gz (17.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page