John - thanks for the reply.
In this case, it's an JQuery .post() call linked to a dropdown menu (https://groups.google.com/d/topic/django-users/tw0lM-QkdGw/discussion).
The dropdown is a common navigation element on every page. It's used to set a session variable that stores which object a user is working on at the
moment (see attached screenshot).
In my webpage:
$('#dropdown_choice').click(function() {$.post("/set_conference", {"current_conference": "conference_name"}, function(data) {alert(data)});});
Then in my view:
# TODO: Set test cookies (although if we're logged in, we can assume cookies works)def set_current_conference(request):if not request.is_ajax() or not request.method == 'POST':return HttpResponseNotAllowed(['POST'])
request.session['current_conference'] = request.POST.get("current_conference")
return HttpResponse('Set current_conference to ' + str(request.POST.get("current_conference")))
So it seems I would need to put the set_test_cookie() logic on every page, since they could make this call from any page with the dropdown. Or is there another way?
How would people normally handle having an AJAX POST call like this to set a session variable?
Or should I just (dangerously) assume that cookies will work automatically? Alternative?
Cheers,
Victor
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/OnnKcnL2oD0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment