Żądanie Django jQuery
$.ajax({
url:'/',
type: "POST",
data: {name: 'name', age: 'age'},
success:function(response){},
complete:function(){},
error:function (xhr, textStatus, thrownError){}
});
I w views.py:
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...
I dostaję:[05 / Oct / 2012 12:03:58] „POST / coś / HTTP / 1.1” 403 2294
Chciałbym wysłać te dane (imię i wiek) przez jQuery do tej funkcji postu w „SomeView”. Jest to ten sam widok, co załadowany szablon, tylko typ żądania jest inny. W przypadku ładowania szablonów get () i postu należy wywołać funkcję post (). Czy to możliwe? Sprawdziłem inne pytania i dostałem to rozwiązanie. To miało działać. Co ja robię źle?