Search code examples
djangodjango-templatesdajaxicedajax

Dajax not working


Dajax is not working, I am not able to understand why. I am using Django 1.7

My ajax.py file looks this:

from dajax.core import Dajax
from dajaxice.decorators import dajaxice_register

@dajaxice_register
def jmc_foundation_tower_number(request, option):

    print("It works!")

My template call is as follows:

<div class='col-lg-3'>
  <select id='id_tower_number' name='tower_number' onchange="Dajaxice.core.views.jmc_foundation_tower_number(Dajax.process, {'option':$this.value})" onclick="Dajaxice.core.views.jmc_foundation_tower_number(Dajax.process, {'option':$this.value})" class='form-control'>
       {% for tower in towers %}
          <option value='{{ tower }}'>{{ tower }}</option>
       {% endfor %}
   </select>
</div>

My urls.py is as follows:

from django.conf.urls import patterns, include, url
from django.contrib import admin

from dajaxice.core import dajaxice_autodiscover, dajaxice_config
dajaxice_autodiscover()


urlpatterns = patterns('',
    url(r'^index$', 'core.views.index', name='index'),

    url(r'^admin/', include(admin.site.urls)),
    url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),

)

Solution

  • Apparently javascript function names with underscores('_') don't work when using functions like onclick.It's better to use functions like somefunction() instead of some_function() to make Dajax work.