Search code examples
javascriptdjangodajax

Dajaxice installation walkthrough


I've tried every which way to install Dajaxice to test it out, but no matter WHAT, I can seem to serve all the JS files appropriately, but can't EVER seem to actually call the functions in ajax.py. Specifically, in my template, I've got a button with

onclick="Dajaxice.dajaxtest.exampleapp.sayhello(my_js_callback);"

yet I ALWAYS get (in developer console in Chrome)

Uncaught TypeError: Cannot read property 'exampleapp' of undefined

In this particular case, it's 'exampleapp', however following other suggestions, I've tried a bunch of different references. It seems the Dajaxice object on my index page simply doesn't have any properties as one would expect, it doesn't have 'myprojectname' (dajaxtest), nor 'myappname' (exampleapp), nor simply 'myfunction'.

As an aside, the documentation for installing Dajaxice doesn't mention including

from dajax.core import Dajax

in ajax.py, but another answer did, so I tried it to no avail.

If you're interested, the exact codebase I'm trying to make work is zipped up and available here: https://docs.google.com/file/d/0B16ANo4rID0PZld5V0p0enlRdUU/edit (Dajax/Dajax ice are installed via pip install django-dajax but really, a perfect answer to my question would be, if you've got Dajaxice up and running, how in the world did you install it, with detailed steps, since it seems the official documentation isn't terribly functional.


Solution

  • I did exactly what the documentation says, and it worked fine (although I only really ever got the example problem working).

    A few things I've noticed:

    1) You shouldn't have to import Dajax to get Dajaxice working (since the former sits on top of the latter).

    2) I think your button onclick should be onclick="Dajaxice.exampleapp.sayhello(my_js_callback);"

    3) You need to add urlpatterns += staticfiles_urlpatterns() to the bottom of your urls.py

    I hope this helps!