私は最終的にこれを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')
)
urls.py:
urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),
url(r'^', include('amish.urls')),
)