0
我終於得到了這個與主視圖返回json數據一起工作......但現在我試圖讓它執行其他視圖,我不能讓它工作!Django + Ajax + jQuery問題
當我嘗試調用AJAX()我得到amishbot/update的server500錯誤
代碼:
我的Ajax腳本:
function sayHello(data){
alert(data.message);
}
function ajax(){
$.ajax({
type: 'POST',
url: '/amishbot/update',
success:func})}
//this is what is called in the html:
onlick="ajax(sayHello);"
我的觀點:
from django.shortcuts import render_to_response
from django.utils import simplejson
from django.http import HttpResponse, HttpResponseRedirect
def home(request):
if request.is_ajax():
d = { 'message':'HELLO!' }
return HttpResponse(simplejson.dumps(d), mimetype="application/json")
return render_to_response('amish/index.html')
def update(request):
if request.is_ajax():
d = {'message':'YALL'}
return HttpResponse(simplejson.dumps(d), mimetype="application/json")
return render_to_response('amish/index.html')
amish/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('amish.views',
(r'^$','home'),
(r'^update/$', 'update')
)
urls.py:
urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),
url(r'^', include('amish.urls')),
)
什麼是你的堆棧跟蹤進入你的服務器日誌? –
所以我把DEBUG變成了False來使用內置的email-to-admin stacktrace ...並且它突然起作用了?是什麼賦予了? – P4r0dy