I have a problem when trying to execute a POST by AJAX, if the function I need to have it inside a [While] that contains a [Form] and I need to modify the dynamic [IDs] of [Script] and [Form], How do I call the function $ (document) .ready (function () {if I can not put it in the head anymore because I have to put it in the while in the body? Do I just remove it? an [ID] in the document, but in this case I have to find all the [IDs] [Submit] that the [While] generates inside the [Form] and I do not know how to put it so that I can execute the post: /
I enclose the principle of the While where it contains the form with its corresponding submits:
while ($fila=mysqli_fetch_array($result5todos, MYSQLI_ASSOC)){
echo "
<table border='3' id='table-ama' >
<tr>
<form METHOD='POST' id='".$fila[ID]."_formulario_EditarObjeto' accept-charset='utf-8'>
<td align='center' class='tdconsulta permisosweb' id='ID' >
<strong style='color:cyan'>ID:</strong> ".$fila[ID]."
";
if(($UAPrivilegios == 'Moderador') or ($UAPrivilegios == 'Administrador') or ($UAPrivilegios == 'AdminFull')){ echo "
<br>
<input TYPE='hidden' readonly='readonly' value='".$fila[ID]."' name='ID'>
<input TYPE='hidden' readonly='readonly' value='".$fila[Tipo]."' name='EditarObjeto_Tipo_Objeto'>
<input TYPE='hidden' readonly='readonly' value='".$fila[Creado_por]."' name='EditarObjeto_Creado_por'>
<INPUT TYPE='SUBMIT' onclick='return confirmar2()' id='".$fila[ID]."_btn-EditarObjeto' VALUE='Actualizar' class='boton-azul' >
<br>
";}
if(($UAPrivilegios == 'Administrador') or ($UAPrivilegios == 'AdminFull')){ echo "
<br>
<input TYPE='hidden' readonly='readonly' value='".$fila[Nom_Obj]."' name='nom_Objeto'>
<input TYPE='hidden' readonly='readonly' value='".$_SESSION["usuarioactual"]."' name='Eliminar_Usuario'>
<INPUT TYPE='SUBMIT' onclick='return confirmar2()' id='".$fila[ID]."_btn-EliminarObjeto' VALUE='Eliminar' class='boton-rojo' style='margin-bottom:4px;'>
";} echo "
</td>
";
And here I attach the Code where it is seen that the [Form] ends, the scripts and where the [While] ends, also a capture of the [Forms] with the buttons that are generated:
Capture: link
echo "
</form>
</tr>
</table>";
?>
<script type="text/javascript">
//Formulario Editar Objeto _ Envio Ajax
$(document).on('ready',function(){
$('#<?php echo $fila[ID]; ?>_btn-EditarObjeto').click(function(){
var url = "./ajaxpaginaobjeto/Formulario_EditarObjeto.php";
$.ajax({
type: "POST",
url: url,
data: $("#<?php echo $fila[ID]; ?>_formulario_EditarObjeto").serialize(),
success: function(data)
{
$('#CrearObjeto_Respuesta').html(data);
}
});
});
});
//Formulario EliminarObjeto _ Envio Ajax
$(document).on('ready',function(){
$('#<?php echo $fila[ID]; ?>_btn-EliminarObjeto').click(function(){
var url = "./ajaxpaginaobjeto/Formulario_EliminarObjeto.php";
$.ajax({
type: "POST",
url: url,
data: $("#<?php echo $fila[ID]; ?>_formulario_EditarObjeto").serialize(),
success: function(data)
{
$('#CrearObjeto_Respuesta').html(data);
}
});
});
});
</script>
<?php
} // Fin del While
?>
I want to send the POST to PHP by AJAX so that the forms are executed instantly without having to reload the screen, but if I can not get it to work I will have no choice but to send the form in a standard way.
A greeting