Ajax, Django: status 200 but throws error instead of success
As you have use $('.commentForm')
to send data of form to backend it will get all forms with class commentForm
and send data of all forms that's the reason its not working .Instead you can change this $('.commentForm').serialize()
to $(this).closest(".commentForm").serialize()
.
Also , you are using #${id}.comments
inside success function of ajax this will override any content inside #${id}.comments
and load new content from url i.e : /posts/comments/..
.So , to avoid this one way would be surround your {% include 'posts/comments.html' %}
with some outer div and then change your selector i.e : #${id}.comments > .yourouterdivclassname
so new content will be loaded inside that div
only thus form will not get removed .