1
When I click on the "Hire" button it makes two requests on the server at once, as I can avoid this?
<button type="button" class="pagar" id="10.00">Contratar</button>
Ajax
$(document).on('click', ".pagar", function () {
preco = $(this).attr('id');
$.ajax({
url: path + 'Usuario/efetuarPagamento',
type: 'POST',
data: {preco: preco},
success: function (response) {
console.log(response);
}, error: function () {
console.log(erro, er);
}
});
});
There will only be two requests if there are two clicks or if you have entered twice the callback of the event. This is what is happening?
– BrTkCa
There are no two clicks, I just click once and it makes two requests, it seems that it is entering twice in the callback
– viniciussvl
The element with the class
.pagar
is created dynamically? Because it is only justified the use ofon
in the document..– BrTkCa
Yes, I am creating several buttons that will do the same thing. I gave console.log(this); and it returns me the button twice..
– viniciussvl
Not tested, but try to see if there is no propagation problem. https://api.jquery.com/event.stoppropagation/
– BrTkCa