Dajax不工作 [英] Dajax not working

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

问题描述

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



我的ajax.py文件看起来如下:

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

@dajaxice_register
def jmc_foundation_tower_number(request,option):

print( 它的工作!)

我的模板调用如下:

 < 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'>
{%in tower in towers%}
< option value ='{{tower}}'> {{tower}}< / option>
{%endfor%}
< / select>
< / div>

我的urls.py如下:



<来自django.conf.urls导入模式的pre> 包含来自django.contrib的url
import admin
$ b从dajaxice.core导入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'))



解决方案

显然是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.

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

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