2
I have a button that when clicked it performs a function:
function searchTradeItems() {
var uid = $("#useruniqid").val();
var iusername = $("#username").html();
var userid = $("#balmung-id").val();
var itemType = $("#trade-type option:selected").val();
var valueType = $("#trade-gold-type option:selected").val();
if (valueType == 5) {
$("#alert-box").show();
$("#mensagem-alert").html("Insira o valor da qualidade entre 0 e 100");
$("#alert-ok").click(function() {
var iquality = $("#alert-value").val();
$("#alert-box").fadeOut(200);
$.ajax({
url: "systems/action-trade.php",
type: "POST",
data: {
uid: uid,
iusername: iusername,
itemType: itemType,
valueType: valueType,
userid: userid,
iname: iname,
iquality: iquality
},
beforeSend: function() {},
success: function(result) {
$("#user-painel-2").html(result);
$("#alert-value").val("");
}
});
});
$("#alert-cancel").click(function() {
$("#alert-box").fadeOut(200);
});
};
//----------------------------------------
}
Until then ok, it takes the typed data and sends with ajax, works, returns the result I want perfectly. But the problem that if I repeat this action he will add the consultations. On the first click it sends an ajax request, if I click again it sends two ajax requests, if I click again it sends 3, and so on... what would be causing this? He made 6 appointments at once. As it was working I only noticed it after a while.
If it’s some silly mistake I beg your pardon, I’m still a beginner.
First, your code becomes easier to read. Second, the function searchTradeItems you only call once? Third, when you say "On the first click...", what event does it trigger? Or rather, what button is it clicking on?
– Douglas Garrido