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>";
}
?>