I have a commenting system that uses ajax.
It generates a div with comments and a reply box via a php loop, meaning the form is repeated over and over again. How do I get var parent to only take the data from the form I submitted? not all of the form fields with the id parent.
$(function () {
$('.reply').on('submit', function (e) {
$.ajax({
type: 'post',
url: '/app/reply',
data: $(this).serialize(),
success: function (data) {
var parent = $('#parent').val();
$("#comment_"+parent).append(data);
var form = document.getElementById("form_" + parent);
form.reset();
}
});
e.preventDefault();
});
});
<form action="" method="POST" class="reply" id="form_<?php echo $comment['id'] ?>">
<textarea id="textArea" name="comment"></textarea>
<input type="submit" name="upload_btn" value="Reply">
<input type="hidden" value="<?php echo $post ?>" name="post">
<input type="hidden" value="<?php echo $comment['id'] ?>" id ="parent" name="parent">
<input type="hidden" value="pop" name="location">
<input type="hidden" value="<?php echo $level ?>" name="level">
</form>