Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
how to avoid from ajax call same function with .scroll(function() if i was click on another div with onclick

in this code you can see that i have two div tags that every one of them have not the same onclick="" function call, the problem is when i click on one of them and then click on enother one the .scroll(function() works also from the first clicked function, this example with alert only,

<div class="first_div_class" onclick="firstFunction();">First Div</div>
<div class="second_div_class" onclick="secondFunction();">Second Div</div>
<div class="result"></div>
<script class="functions">

        function firstFunction(){

          var one = '<?php echo $someValueOne; ?>';
          var two = '<?php echo $someValueTwo; ?>';                      

                    $.ajax({
                        type:'GET',
                        url:'getSomethingOne.php',
                        data: {
                            'SomethingOneInFirstFunction':one,
                            'SomethingTwoInFirstFunction':two
                        },
                       
                        success:function(data){
                            
                $('.result').html(data);

                                         },
        
            });
            
            $('.result').scroll(function(){
   

                                  alert("Hello! to the first box!!");

            });
            
        }

        function secondFunction(){
    
          var one = '<?php echo $someValueOne; ?>';
          var two = '<?php echo $someValueTwo; ?>';   
                
                    $.ajax({
                        type:'GET',
                        url:'getSomethingTwo.php',
                        data: {
                            'SomethingOneInSecondFunction':one,
                            'SomethingTwoInSecondFunction':two
                        },
                       
                        success:function(data){
                            
                $('.result').html(data);

                                         },
        
            });
            
            $('.result').scroll(function(){
   

                                  alert("Hello! to the second box!!");

            });
            
        }
</script>

even if you will try without the ajax call and only with on click function its will continue the first clicked function scroll call,

how can i stop this?...

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should set your listener for one-time usage. The problem is that you are setting a new scroll handler for the same HTML element on every call of your function and they are never removed.

$('.result').one('scroll', function() {...})
about 4 years ago · Juan Pablo Isaza Relatório

0

i was added to the start of each function

$(".result").unbind();

thank you epascarello

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda