In order to use dajax you should install django-dajaxice before. Please follow these instructions here.

Installing Dajax

Install django-dajax using easy_install or pip:

$ pip install django_dajax
$ easy_install django_dajax

Add dajax in your project inside INSTALLED_APPS:


Create a new file inside your app with your own dajax functions:

from dajax.core import Dajax
def multiply(request, a, b):
    dajax = Dajax()
    result = int(a) * int(b)
    return dajax.json()

Include dajax in your <head>:

Dajax supports up to four JS libraries. You should add to your project base template the one you need.

For example for jQuery:

{% static "/static/dajax/jquery.dajax.core.js" %}

Use Dajax

Now you can call your ajax methods using‘Dajax.process’):

<button onclick="Dajaxice.example.myexample(Dajax.process);">Click here!</button>

The function _Dajax.process_ will process what the server returns and call the appropriate actions. If you need your own callback, you can change the callback with a function like:

function my_callback(data){
    /* Your js code */

And use it as:

<button onclick="">Click here!</button>