Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!