我终于让它与返回 json 数据的主视图一起工作......但现在我试图让它执行其他视图,但我无法让它工作!
当我尝试调用 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')
阿米什/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('amish.views',
(r'^$','home'),
(r'^update/$', 'update')
)
网址.py:
urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),
url(r'^', include('amish.urls')),
)