0

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.

Alex Whittemore
  • 1,015
  • 10
  • 19

2 Answers2

1

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!

moarCoffee
  • 1,289
  • 1
  • 14
  • 26
  • So I revisited Dajaxice after a week or two break from doing Django backend coding. When I tried it again (on a Django 1.5 installation, FWIW), everything came together smoothly, and I'm not quite sure what my real issue was. I will say: 1) (3) isn't strictly correct, you don't need to add the staticfiles_urlpatterns() if you simply have the staticfiles app enabled. 2) it could have been that I wasn't running ./manage.py collectstatic. I'm not sure why that'd matter - my ajax.py changes are picked up in dajaxice js even when I don't run it. But previously, they weren't registering. – Alex Whittemore Mar 20 '13 at 20:33
0

I suppose you haven't added appname in your project settings.py inside INSTALLED_APPS. like this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dajaxice',
    'simple',
)