0
while($reg = $stmt->fetch(PDO::FETCH_OBJ))
{
$id = $reg->id;
echo "<div class='altpost' id='$id'></div>";
echo "<form id='$id' class='faltpost' method='post' action='altp.php'><input name='naltpost' type='number' value='$id' hidden/><button>editar</button></form>";
}
jQuery(document).ready(function(){
jQuery('.faltpost').submit( function(){
var dados = jQuery(this).serialize();
jQuery.ajax({
url: "altp.php",
type: "POST",
data: dados,
success: function(data)
{
var id = $('.altpost').attr("id");
$(document.getElementById(id)).html(data);
}
});
return false;
});
});
When I click on any button of any post only activates the effect in the first post, the problem is that the buttons have the same name, looking for a way to specify each button. I tried jQuery('.faltpost'). attr("id"). Ubmit, but it didn’t work. the "$id" is the number of the post, I’m taking a beating from JQUERY who help me is sure I will give score.
The
div
and theform
have the same value inid
? This is not possible. The attributeid
defines a single element on the page and no more than one element with the sameid
. Read more on W3C specification.– Woss
Because I had put class and changed it to id, I forgot that, I will change to class again, but the problem here is how to specify the button in Jquery. I click and select all buttons, because I don’t know how I do to grab a specific button and put in Jquery with while, because it repeats all posts with class with the same name. When I try to play for Jquery it takes them all at once, because I cannot specify in Jquery:
– Luizinho
The
submit
form is working correctly? Only the result display that appears on all elements?– Woss
The problem is in this line here: "jQuery('. faltpost'). Submit( Function(){" The class faltpost is in all buttons. I want to specify each of them.
– Luizinho
It’s working normally, but only in the first post, if I press the bottom post, the effect works in the first post and in any other post the same thing.
– Luizinho
Yes, but you need to do this, but the function will be executed only for the form that is submitted. The real problem is in the function
success
. You’re always getting the value ofid
of$('.altpost')
, that will always be the first.– Woss
The first time I tried I was doing it this way
– Luizinho
Success: Function(data){ $(".altpost"). html(data); }
– Luizinho
But so the effect goes to all posts
– Luizinho
Do you have any suggestions so I can solve this problem?
– Luizinho