I wanted to play with dajax for my actual django project. I stardet looking at the simple form example on the website, but i cannot get it to work correctly. I keep on getting this error (with firebug) "Error: Dajax is not defined"
Also i was trying to implement the dajaxice example, but i get this other error:
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!"})
Here are my files (ajax.py and javascript.js) and my view function. The html template is analog to the one in the website.
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){
aler开发者_高级运维t(data.message);
}
my view.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)
)
i have settings.py configured like they say on the main website. i don't know what's wrong, google doesn't seem to help (any search for dajax/dajaxice gives results for ajax... pretty obvious, pretty annoying...) any hint/help?
i'm answering my own question since i figured it out. it was a stupid problem&mistake...
i just forgot to include
<script type="text/javascript" src="{{ MEDIA_URL }}jquery.dajax.core.js"></script>
into my html template. hope this is helpful for somebody, oneday! if you're not using jquery, try one of the others
精彩评论