达贾克斯不工作 [英] Dajax not working

查看:16
本文介绍了达贾克斯不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dajax 不工作,我不明白为什么.我正在使用 Django 1.7

我的 ajax.py 文件如下所示:

from dajax.core import Dajax从 dajaxice.decorators 导入 dajaxice_register@dajaxice_registerdef jmc_foundation_tower_number(请求,选项):打印(它有效!")

我的模板调用如下:

<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'>{% 为塔中塔%}<option value='{{ 塔 }}'>{{ 塔 }}</option>{% 结束为 %}</选择>

我的urls.py如下:

from django.conf.urls 导入模式,包含,url从 django.contrib 导入管理员从 dajaxice.core 导入 dajaxice_autodiscover, dajaxice_configdajaxice_autodiscover()urlpatterns = 模式('',url(r'^index$', 'core.views.index', name='index'),url(r'^admin/', 包含(admin.site.urls)),网址(dajaxice_config.dajaxice_url,包括('dajaxice.urls')),)

解决方案

显然带有下划线('_')的 javascript 函数名在使用 onclick 等函数时不起作用.最好使用像 somefunction() 这样的函数而不是 some_function() 使 Dajax 工作.

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')),

)

解决方案

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.

这篇关于达贾克斯不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆