首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dajax/dajaxice问题:"Dajax未定义“和”语句后缺少}“

Dajax/dajaxice问题:"Dajax未定义“和”语句后缺少}“
EN

Stack Overflow用户
提问于 2011-07-25 21:14:50
回答 1查看 3.5K关注 0票数 1

我想在我的实际django项目中使用dajax。我开始看网站上的simple form example,但我不能让它正常工作。我一直收到这个错误( firebug) " error : Dajax is not defined“

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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
function the_callback(data){
        alert(data.message);
}

我的view.py

代码语言:javascript
复制
from django.shortcuts import render_to_response

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

urls.py

代码语言:javascript
复制
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,就像他们在主网站上说的那样。我不知道出了什么问题,google似乎没有帮助(任何搜索dajax/dajaxice都会给出ajax的结果……非常明显,非常烦人...)有什么提示/帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-26 16:19:46

我在回答我自己的问题,因为我弄清楚了。这是一个愚蠢的问题和错误。

我只是忘了加进去

代码语言:javascript
复制
<script type="text/javascript" src="{{ MEDIA_URL }}jquery.dajax.core.js"></script>

添加到我的html模板中。希望有一天,这能对某些人有所帮助!如果您没有使用jquery,请尝试使用one of the others

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6816705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档