Let's start with the fact that I need to display comments on the page. The first 5 comments are shown, and the rest I activate via ID, adding 10 comments each

project.php:

<div class='pview-comm-more'></div> <div class="text-aligndd"><a href="#" id="showmorecomm">Вывести еще комментарии</a></div> if( $show_more_comm ) { ?> var numb = 0.6; $("#showmorecomm").bind("click", function(){ loadProjComment(numb,'<?=$proj['id'];?>','.pview-comm-more'); $(this).show(); numb+=1; return false }); <?php } ?> 

This is basic.js

 function loadProjComment(num, projid, contid) { var post_comm_str = "projid=" + projid + "&pi=" + num + "&pn=10"; $.ajax({ type: "POST", url: req_ajx_host+"ajx/projcomms/", data: post_comm_str, dataType: "text", success: function(data){ try { $(contid).html(data); } catch(e1) { // Some errors occure while retieving city list so do nothing $(contid).html("Error loading data..."); } } }); } 

From basic.js are transferred to ajxController.class.php

 public function action_projcomms(){ $projid = $this->getReqParam("projid", 0); $pi = $this->getReqParam("pi", 0); $pn = $this->getReqParam("pn", 0); if ($pi > 0 && $pn > 0) { $catLib = new Catalog($this->db, $this->LangId); $coms = $catLib->Item_Comments($projid, 1, $pi, $pn); $html = $this->view->reqlist_comments($coms); $this->view->render_html($html); } } 

Then 10 messages are added in the method.

 public function reqlist_comments($coms){ for( $i=0; $i<count($coms); ++$i ) { ($coms[$i]['pic']) ? $psrc = (WWWHOST.$coms[$i]['pic']) : $psrc = (WWWHOST.'img/no-pic.png'); ?><div class="pview-comment-it pview-comm"> <div class="row"> <div class="col-md-3 col-xs-3 col-lg-3 pview-comm-border"> <div class="pview-comm-usr"> <a href="<?=$this->Page_BuildUrl("users", "viewrev/".$coms[$i]['author_id'])?>"><img class="usr-comm-pic" src='<?=$psrc?>' alt="<?=( $coms[$i]['account_type'] == USR_TYPE_PERS ? $coms[$i]['name'].' '.$coms[$i]['fname'] : $coms[$i]['orgname'] )?>" title="<?=( $coms[$i]['account_type'] == USR_TYPE_PERS ? $coms[$i]['name'].' '.$coms[$i]['fname'] : $coms[$i]['orgname'] )?>" height="50px" width="50px"> <span class="pview-usr-ico pview-com-usr"><?=( $coms[$i]['account_type'] == USR_TYPE_PERS ? $coms[$i]['name'].' '.$coms[$i]['fname'] : $coms[$i]['orgname'] )?></span></a> </div> </div> <div class="col-md-9 col-xs-7 col-lg-10"> <div class="pview-comm-txt"> <div class="pview-comment-msg proj-size-fix"><?=$coms[$i]['content']?></div> <span class="pview-comment-dt proj-size-data"><?=$this->localize->get("projview", "dt-comment").': '.$coms[$i]['add_dt']?></span> </div> </div> </div> </div> <?php } } 

But when I click again on the inscription "Show more comments," my 10 comments previously displayed are replaced with a new batch of comments. How to make it so that each time the output does not replace the previous one?

  • slight retreat. why do you request comments using the POST method? - Invision

2 answers 2

Replace

 $(contid).html(data); 

On

 $(contid).append(data); 
  • Thanks, helped! - Artur Cooper

$(contid).html(data); => $(contid).append(data);