【问题标题】:Dajax/dajaxice problems: "Dajax is not defined" and "missing } after statement"Dajax/dajaxice 问题:“未定义 Dajax”和“缺少 } after statement”
【发布时间】:2011-07-25 13:14:50
【问题描述】:

我想在我的实际 django 项目中使用 dajax。我开始查看网站上的simple form example,但我无法让它正常工作。 我不断收到此错误(带有萤火虫)“错误:未定义 Dajax”

我也试图实现dajaxice example,但我得到了另一个错误:

Error: missing } after function body
Source File: http://localhost:8000/dajaxice/dajaxice.core.js
Line: 30, Column: 52
Source Code:
    alert("data.message")({"message": "Buuuuuuuuu!"})

这是我的文件(ajax.py 和 javascript.js)和我的视图函数。 html模板类似于网站中的模板。

ajax.py

from django.utils import simplejson
from dajaxice.core import dajaxice_functions, Dajaxice
from dajax.core import Dajax

def myexample(request):
    return simplejson.dumps({'message':'Buuuuuuuuu!'})

dajaxice_functions.register(myexample)


def updatecombo(request, option):
    dajax = Dajax()
    options = [ ['Madrid','Barcelona','Vitoria','Burgos'],
                ['Paris','Lille','Nantes','Lyon'],
                ['London','Manchester','Liverpool','Someother'],]
    out = ""
    for o in options[int(option)]:
         out += "%s<option value='#'>%s" % (out,o,)
    dajax.assign('#combo2', 'innerHTML', out)
return dajax.json()

dajaxice_functions.register(updatecombo)

javascript.js

function the_callback(data){
        alert(data.message);
}

我的观点.py

from django.shortcuts import render_to_response

def basic_view(request):
        return render_to_response('test.html', {}, context_instance = RequestContext(request))

urls.py

import os
from django.conf import settings
from django.conf.urls.defaults import *
from dajaxice.core import dajaxice_autodiscover
from dajax_test.tester.views import *


from django.contrib import admin
admin.autodiscover()

dajaxice_autodiscover()

site_media = os.path.join(
        os.path.dirname(__file__), 'site_media'
)

urlpatterns = patterns('',

        (r'^%s/' % settings.DAJAXICE_MEDIA_PREFIX, include('dajaxice.urls')),
        (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': site_media},),


        (r'^dajaxice/$', basic_view)
)

我已经按照他们在主网站上所说的那样配置了 settings.py。 我不知道出了什么问题,谷歌似乎没有帮助(任何搜索 dajax/dajaxice 都会给出 ajax 的结果......很明显,很烦人......)任何提示/帮助?

【问题讨论】:

  • 更新:通过easy_install更新dajaxice我设法让按钮工作(myexample函数现在工作)。我仍然在 updatecombo 函数上有错误(“未定义 Dajax”)

标签: django


【解决方案1】:

我正在回答我自己的问题,因为我想通了。这是一个愚蠢的问题和错误......

我只是忘了包含

<script type="text/javascript" src="{{ MEDIA_URL }}jquery.dajax.core.js"></script>

进入我的 html 模板。希望这对某人有所帮助,有一天! 如果您不使用 jquery,请尝试 one of the others

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-21
    • 2012-04-22
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 2012-04-20
    相关资源
    最近更新 更多