Guest User

Untitled

a guest
Feb 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class OperationCreate(CreateView):
  2.  
  3. model = Operation
  4. form_class = OperationForm
  5. success_url = reverse_lazy('manage_operations')
  6.  
  7. def form_valid(self, form):
  8. (...)
  9. form.save()
  10. return JsonResponse({'result': 'success'})
  11.  
  12. def form_invalid(self, form):
  13. form.save()
  14. return JsonResponse({'result': 'error'})
  15.  
  16. function postForm(url, form_selector) {
  17. var form = $(form_selector);
  18. var csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value')
  19.  
  20. form.submit(function () {
  21. $.ajax({
  22. headers: { 'X-CSRFToken': csrf_token },
  23. type: 'POST',
  24. url: url,
  25. data: form.serialize()
  26. });
  27. });
  28. };
Add Comment
Please, Sign In to add comment