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 can I put another form on the same page with Ajax request for another file.
Notice that the Form ID varies according to the bank's registration ( $ i ) because ajax runs on all bank records.