2
Good afternoon guys, I’m in the following situation:
I have my page called Stock.html, it contains the Jqueries events belonging to it, for now everything normal, but on this page there is a button called Filter that opens a modal and fills it (with ajax call) with page content called Estoque_filter.html, however in it there is a Jquery event that calls another ajax and makes internal changes to the session.
Well my problem is, every time I click on the Filter button I normally run the tasks, close the modal and click again on the button, the Jquery event that is on the Stock page_filter.htlm is duplicated, tripled, etc depending on how often I click to load the modal, so making several times the call of the second ajax mentioned above.
Following example:
Stock.html
<html>
<head>
</head>
<body>
<button id="filtro">Filtro</button>
<div id="modal" style="display:none;">
</div>
<script type="text/javascript">
$("#filtro").click(function(){
OpenModal('Estoque_filter.html');
});
function OpenModal(url){
$.ajax({
method:"GET",
url: url,
async: true
}).done(function (data){
$("#modal").html(data);
$("#modal").css("display","block");
});
}
</script>
</body>
</html>
Estoque_filter.html
<html>
<head>
</head>
<body>
<button id="altera">Altera Sessão</button>
<script type="text/javascript">
$("#altera").click(function(){
$.ajax({
method:"GET",
url: 'altera_sess.php',
async: true
}).done(function (data){
$("#modal").css("display","none");
});
});
</script>
</body>
</html>
After clicking not only disable the button immediately when you click it and enable it in the ajax answer?
– Bruno
No, because this button can be clicked several times, the problem is at the time I call again the modal and it fills the Jquery event again. Then he calls the event that already existed and the one just placed with Jquery
– Amarildo Martins