I have a django template like this :
{% for comment in service.comments.all %}
{{comment.comment}} -- commented by {{comment.user}}<br/>
{% for reply in comment.comment_replies.all %}
{{reply.comment_reply}} -- replied by {{reply.user}}<br/>
{% endfor %}
<form id="comment-replyform" action="/comment/reply/{{comment.id}}/" method="post">{% csrf_token %}
{{ comment_reply_form.as_p }}
<input type="submit" name="submit" value="Reply">
</form>
{% empty %}
No comments
{% endfor %}
Here I want to reply to comment using ajax.. so that page wont refresh.. I have written javascript code for this ..
$('#comment-replyform').on('submit', function(event){
event.preventDefault();
$.ajax({
url: $(this).attr('href'),
success: function(data) {
alert("Success");
}
});
})
Here I see a success alert for only first comment reply form.. When I send from another comment reply field( because there might be many comment reply form for many comments).. It does not call ajax and refresh the page...
How can I post this form with comment message ?