$.ajax({
url:'/',
type: "POST",
data: {name: 'name', age: 'age'},
success:function(response){},
complete:function(){},
error:function (xhr, textStatus, thrownError){}
});
而且在views.py:Django的jQuery的POST请求
class SomeView(generic_views.TemplateView):
template_name = 'something.html'
def get(self, request, *args, **kwargs):
...something...
return self.render_to_response(context)
def post(self, request, *args, **kwargs):
name = request.POST['name']
age = request.POST['age']
...something...
我也得到:[05月/ 10月/ 2012 12时03分58秒] “POST /事/ HTTP/1.1” 403 2294
我想通过jQuery来发送这个数据(姓名和年龄)这个帖子功能“SomeView”。这与加载模板的视图相同,只是请求类型不同。在get()模板加载后,应该调用post()函数。可能吗?我检查了其他问题并获得了此解决方案。它应该是工作。我究竟做错了什么?
对我使用FormView的其他网站。但在这种情况下,我不能(长话短说)。 :) 现在的事情,但在终端,我看到 [05/Oct/2012 15:08:11]“POST /东西/ HTTP/1.1”500 9499 – premik91
500只是一个服务器错误。这可能是由于你的post方法中的任何python错误。 –
但是,应该显示,因为我处于调试模式,不应该吗? – premik91