foreach ($result as $articles){?>
<p><?echo $articles['title'];?></p>
<p><?echo $articles['content'];?></p>
foreach ($comm as $comment){?>
<div class = "comment_show">
<p><? echo $comment['user'];?></p>
<p><? echo $comment['comm_text'];?></p>
</div>
<form class = "comment_form" action = "send.php" action ="POST">
<input type ="hidden" name ="article_id" value ="<? echo $articles['id']" class = "content_id"
<input type ="text" name ="username" class = "userlogin">
<textarea name ="comment" class = "comm_cont">
<input type ="button" name ="submit" class = "submit">
</form>
<?php
}
}
?>
Подскажите пожалуйста, как исправить код в js чтобы он выполнялся для каждого элемента всех форм, выводящихся в цикле php
<p><?echo $articles['title'];?></p>
<p><?echo $articles['content'];?></p>
foreach ($comm as $comment){?>
<div class = "comment_show">
<p><? echo $comment['user'];?></p>
<p><? echo $comment['comm_text'];?></p>
</div>
<form class = "comment_form" action = "send.php" action ="POST">
<input type ="hidden" name ="article_id" value ="<? echo $articles['id']" class = "content_id"
<input type ="text" name ="username" class = "userlogin">
<textarea name ="comment" class = "comm_cont">
<input type ="button" name ="submit" class = "submit">
</form>
<?php
}
}
?>
Код:
$(document).ready(function(){
$('.submit').on('click', function(e) {
e.preventDefault();
var content_id = $('.content_id').val();
var username = $('.userlogin').val();
var message = $('.comm_cont').val();
var url = $('.comment-form').attr('action');
//e.preventDefault();
$.ajax({
url: url,
type: "POST",
data: {
"post_id": content_id,
"login": username,
"comment": message,
"submit": $(".submit").val()
},
cache: false,
dataType: 'json',
success: function(response){
$('.comment_text').val('');
$('.comment_show').append(response.username + response.login + response.comment + response.pubdate);
}
});
});
});