[Answered ]-Ajax powered form submission working only once Django


Problem 1 sounds like it could be related to Django’s built-in CSRF protection. Try inspecting the HTTP requests with a tool like Charles or Firebug and check to see if the same CSRF token is being sent twice. Unless CSRF protection has been explicitly disabled for a view, the form submission would be rejected the second time around unless the token is updated.

The docs have a section on dealing with this in Ajax code.

Although I couldn’t say for sure, perhaps it’s possible that Problem 2 has to do with jQuery’s selection process for which fields it includes when it serializes. From their docs:

Note: Only “successful controls” are serialized to the string. No
submit button value is serialized since the form was not submitted
using a button. For a form element’s value to be included in the
serialized string, the element must have a name attribute. Values from
checkboxes and radio buttons (inputs of type “radio” or “checkbox”)
are included only if they are checked. Data from file select elements
is not serialized.

Leave a comment