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

112
Visualizações
Jquery function not working properly with php loop

I am working with jQuery and PHP. I am using AJAX in the controller and I am getting "Feeds" (Posts) in a PHP loop.

The issue is that whenever I click on any button in that loop it shows me the alert multiple times instead of one time. How can I solve this?

Right now I just alert a simple message for the test but the alert box shows more than 1 time after a single click. I just want that it should alert only one time so I can write/execute my function further.

Thank you in advance.

<?php
  function fetch()
  {
    $FeedId;
    (dynamic) $FeedData = $this
      ->M_main
      ->GetFeedData(); // getting feed data from database

    foreach ($FeedData as $feeds)
    {
      if ($feeds['flag'] == "feed")
      {
        $GetFeedComments = $this
          ->M_main
          ->GetFeedsComment($FeedId);

        $TotalFeedsComments = $GetFeedComments['TotalRows'];
        if ($TotalFeedsComments > 1)
        {
          $Loads = '<div class="show_more_main" id="show_more_main' . $postID . '">
                      <input type="hidden" name="fixs" value="' . $postID . '" id="fixs">
                      <input type="hidden" name="MinValue" value="' . $postID . '" id="MinValue">
                      <input type="hidden" name="MaxValue" value="' . $postID . '" id="MaxValue">
                      <span id=' . $postID . ' data-val=' . $postID . ' data-status=' . $postID . ' class="show_more" title="Load more posts">Show more</span>
                      <span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
                    </div>';
        }
        else
        {  
          $Loads = "";
        }
      }
    }

    $paths = base_url() . "Main/AddComments";
    echo "<script>
      $('.show_more').click(function (e) {
        e.preventDefault(); 
        alert("Helloworld"); 
      });
    </script>";  
  }    
?>
about 4 years ago · Juan Pablo Isaza
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