文章收藏功能问题

623次浏览 更新日期:2022-04-06 15:33:56 分类:程序交流 评论:3

文章中收藏后,当时能显示已收藏,刷新后又只显示收藏,如果再收藏回去掉已收藏内容,要能直接加判断显示正确的结果最好,不要重复收藏

我来说两句
  • 群里我发解决办法了
    1
    回复
  • yzmcms
    yzmcms 官网认证 1年前
    最新版的yzmcms是支持收藏回显的,请参考下默认模板即可
    0
    回复
  • zylmc
    zylmc 2年前
    改的很好,给你个大大的赞!!!我觉得开始检查是否收藏是对的。
      
    $(function (){
          checkfavorite();
        });
        function add_favorite(title) {
          $.ajax({
            type: 'POST',
            url: '{U("api/index/favorite")}',
            data: 'title='+title+'&url='+'{$url}',
            dataType: "json",
            success: function (msg) {
              if(msg.status == 1){
                alert('收藏成功');
                $("#favorite").html('已收藏');
              }else if (msg.status ==2){
                $("#favorite").html('收藏');
                alert('取消收藏成功');
              }else{
                alert('请先登录!' );
                window.location.href="{url_referer(get_url())}";
              }
            }
          });
        }
        function checkfavorite(title) {
            $.ajax({
                type: 'POST',
                url: '{U("api/index/check_favorite")}',
                data: '&url='+location.href,
                dataType: "json",
                success: function (msg) {
                  if(msg.status == 1){
                    $("#favorite").html('已收藏');
                  }
                }
            });
        }
    0
    回复
作者信息
发布见解
发内容 回顶部