0
I can make an Ajax request as follows:
HTML
<div class="resultado_debito<?php echo $i ?>">
<span class="ruim"><br>Inadiplente</span><br>
<form method="post" id="quitar_debito<?php echo $i ?>" novalidate="novalidate">
<input type="hidden" name="pagamento" value="sim" class="pagamento">
<input type="hidden" name="i" value="<?php echo $i ?>" class="i">
<input type="hidden" name="id_empresa_pagamento" value="<?php echo $row["id"]?>" class="id_empresa_pagamento">
<input type="submit" value="Quitar">
</form>
</div>
Js Ajax
$(document).ready(function() {
$("form").submit(function() {
//Remove a palavra quitar_ e deixa somente "debitoX"
const formID = $(this).attr('id').replace("quitar_", "");
//Captura o elemento que sofreu o evento de "submit"
const formDetails = $(this);
$.ajax({
type: "POST",
url: 'enviar_pagamento.php',
data: formDetails.serialize(),
success: function (data) {
// Inserting html into the result div
$('.resultado_'+formID).html(data);
},
error: function(jqXHR, text, error){
// Displaying if there are any errors
$('.resultado_'+formID).html(error);
}
});
return false;
});
});
My question would be how I can put one more form on the same page with Ajax request for another file.
Note that the Form ID varies according to the database record ($i), because ajax runs on all bank records.
Well, you’re already receiving the requests that any form fires... With respect to the target, each form can have its action itself, via HTML. This way, forget the id. Return to this function, the form you gave to Submit. This way, you can edit the correct tag. Can you understand or need help?
– DiegoSantos
I did not understand very well, would just put an action in each form? Could you give me an example?
– Wagner Martins Bodyboard
I will reply with a suggestion
– DiegoSantos