전에 올렸는 질문인데 잘 해결되지 않아서 다시 올렸습니다!

전에 올렸는 질문인데 잘 해결되지 않아서 다시 올렸습니다!

QA

전에 올렸는 질문인데 잘 해결되지 않아서 다시 올렸습니다!

본문


 
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
run_event('bbs_good_before', $bo_table, $wr_id, $good);
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 297;
$thumb_height = 212;
$list_count = (is_array($list) && $list) ? count($list) : 0;
?>
 
<div class="pic_li_lt">
   
<h2 class="lat_title"><a href="<?php echo get_pretty_url($bo_table); ?>"><?php echo $bo_subject ?></a></h2>
 
    <ul>
    <?php
    for ($i=0; $i<$list_count; $i++) {
       
        $img_link_html = '';
       
        $wr_href = get_pretty_url($bo_table, $list[$i]['wr_id']);
        //좋아요
        $good_href = G5_BBS_URL.'/good.php?bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].'&good=good';
        //싫어요
        $nogood_href = G5_BBS_URL.'/good.php?bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].'&good=nogood';
 
    ?>
   
        <li>
            <?php echo $img_link_html; ?>
            <?php
            if ($list[$i]['icon_secret']) echo "<i class=\"fa fa-lock\" aria-hidden=\"true\"></i><span class=\"sound_only\">비밀글</span> ";
 
            echo "<a href=\"".$wr_href."\" class=\"pic_li_tit\"> ";
           
            if ($list[$i]['ca_name']) {
                echo  "<span class =\"lt_ca\">" ."[{$list[$i]['ca_name']}]". "</span>";
            }
 
            if ($list[$i]['is_notice'])
                echo "<strong>".$list[$i]['subject']."</strong>";
            else
                echo $list[$i]['subject'];
       
                    echo "</a>";
 
 
        ?>
 
 
            <div class="lt_info">
 
<?php
 
$sql = " SELECT * FROM g5_board_good WHERE mb_id='{$member['mb_id']}' AND bo_table='${$bo_table}' AND bg_flag='good' AND wr_id='$list[$i]['wr_id']' ";
$memberGood = sql_fetch($sql);
 
 
  if ($memberGood) {
    echo "<a href=\"".$good_href."\"  id=\"lt_good\" class=\"lt_v_good\" >" . "<span class=\"lt_good\">" . " <i class=\"fa fa-heart\"></i><strong>{$list[$i]['wr_good']}</strong>". "</span>";        
    echo "<b class=\"lt_v_act_good\"></b>";
    echo "</a>";
    // 내가 좋아요를 눌렀을때 출력
  } else {
    echo "<a href=\"".$good_href."\"  id=\"lt_good\" class=\"lt_v_good\">" . "<span class=\"lt_good\">" . " <i class=\"fa fa-heart-o\"></i><strong>{$list[$i]['wr_good']}</strong>". "</span>";        
    echo "<b class=\"lt_v_act_nogood\"></b>";
   echo "</a>";
    // 내가 좋아요를 누르지 않았을때 출력
  }
 
?>
<!-- ---------------------------------------------------------------- -->

 
<?php }  ?>
 
<script>
$(function() {
    // 추천, 비추천
    $(".lt_v_good").click(function() {
        $tx = $(this).children(".lt_v_act_good");
 
 
        excute_good(this.href, $(this), $tx);
        return false;
    });
});
 
// $(function() {
//     // 추천, 비추천
//     $(".lt_v_good , .lt_v_nogood").click(function() {
 
//         if($memberGood){
//         $tx = $(this).children(".lt_v_act_good");
//         }
//         else{
//         $tx = $(this).children(".lt_v_act_nogood");
//         }
//         excute_good(this.href, $(this), $tx);
//         return false;
//     });
// });
 
</script>
 
<script>
function excute_good(href, $el, $tx)
{
    $.post(
href,
        { js: "on" },
        function(data) {
if(data.error) {
alert(data.error);
                return false;
            }

 
            if (data.count) {
    $el.find("strong").text(number_format(String(data.count)));
    $el.find("i").removeClass('fa fa-heart-o').addClass('fa fa-heart');
}
 
if(data.msg){
    $tx.stop().hide();
    $tx.text(data.msg);
    $tx.fadeIn(200).delay(2500).fadeOut(200);
}

 
        }, "json"
    );
}
</script>

 
 
    <?php if ($list_count == 0) { //게시물이 없을 때  ?>
    <li class="empty_li">게시물이 없습니다.</li>
    <?php }  ?>
    </ul>
    <!-- <a href="<?php echo get_pretty_url($bo_table); ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span>더보기</a> -->
 
</div>
</script>

 

 

저 회원이 저 하트를 눌렀을 때 숫자와 동시에 빨간색 하트가 나오고 다시 추천 취소를 누르면 저렇게 흰색하트와 숫자가 줄어들도록 하고싶은데 지금은 누르면 빨간색이 되는데 다시 하얗게 돌아오지 않습니다 

어디가 문제인지 잘 모르겠어서 도움을 요청합니다 도와주세요!!991484400_1659710762.9965.png

이 질문에 댓글 쓰기 :

답변 2

실시간으로 하시려면 api를 만드셔야해요

지난번에 질문 올리셨을때 답변 드렸던건 첫 로드나 리로드 시에만 적용되는 동기처리였습니다

스크립트로 처리 할수밖에 없어요 제이쿼리로 설명한다면

if(data.count) {

$(this).addClass('red');

} else {

$(this).removeClass('red');

}

 

이런식으로 해야될것같은데요

답변을 작성하시기 전에 로그인 해주세요.
전체 76
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT