I have a Django view, named vote. It is protected by a @login_required decorator, and in normal use works completely fine.
I decided it would be a worthwhile idea to start looking into ajax and javascript to make the system more dynamic, and so I implemented something like the below for my first try:
$(function() {
$(".vote").click(vote);
});
var vote = function() {
pk = $(this).attr('pk');
$.ajax({
type: "POST",
data: "pk=" + $(this).attr("pk"),
url: "/link/" + $(this).attr("pk") + "/vote/",
});
};
Which successfully POSTS to the correct URL. When I look at the output with firebug, I find I'm getting 500 errors. I've included the snipped from https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax into my pages, which I had thought would solve the CSRF issue, however it appears not to have done so.
Wondering whether I'm missing something obvious!
Thanks!