dstew32424 2018-05-13 09:47
浏览 46

删除帖子功能不正常

I have a delete function written in PHP and jQuery. that function does is deleting a post that the current user posted (tracks current user_id). But when i Click "Delete tweet" it doesn't delete it, and I don't understand why because the code doesn't work, it looks okay to me.

Thanks for your time and help.

Images:

Console: Console

Network tab:

enter image description here

Code snippets below:

$(function(){
    $(document).on('click', '.deleteTweet', function(){
        var tweet_id = $(this).data('tweet');

        $.post('http://localhost:8888/twitter/core/ajax/deleteTweet.php', {showpopup:tweet_id}, function(data){
            $('.popupTweet').html(data);
            $('.close-retweet-popup,.cancel-it').click(function(){
                $('.retweet-popup').hide();
            });
        });
    });

    $(document).on('click','.delete-it', function(){
        var tweet_id = $(this).data('tweet');

        $.post('http://localhost:8888/twitter/core/ajax/deleteTweet.php', {deleteTweet:tweet_id}, function(){
            $('.retweet-popup').hide();
            location.reload();
        });
    });

    $(document).on('click', '.deleteComment', function(){
        var tweet_id    = $(this).data('tweet');
        var commentID   = $(this).data('comment');

        $.post('http://localhost:8888/twitter/core/ajax/deleteComment.php', {deleteComment:commentID,tweet_id:tweet_id});
        $.post('http://localhost:8888/twitter/core/ajax/popuptweets.php', {showpopup:tweet_id}, function(data){
            $('.popupTweet').html(data);
            $('.tweet-show-popup-box-cut').click(function(){
                $('.tweet-show-popup-wrap').hide();
            });
        });
    });
});
<?php 
    include '../init.php';
    if(isset($_POST['deleteTweet']) && !empty($_POST['deleteTweet'])){
      $tweet_id  = $_POST['deleteTweet'];
      $user_id   = $_SESSION['user_id'];
      //get tweet data from tweet id
      $tweet     = $getFromT->tweetPopup($tweet_id);
      //create link for tweet image to delete from
      $imageLink = '../../'.$tweet->tweetImage;
      //delete the tweet from database
      $getFromT->delete('tweets', array('tweetID' => $tweet_id, 'tweetBy' => $user_id));
      //check if tweet has image
      if(!empty($tweet->tweetImage)){
        //delete the file
        unlink($imageLink);
      }
     }

    if(isset($_POST['showpopup']) && !empty($_POST['showpopup'])){
       $tweet_id  = $_POST['showpopup'];
       $user_id   = $_SESSION['user_id'];
       $tweet     = $getFromT->tweetPopup($tweet_id);
    
?>
<div class="retweet-popup">
  <div class="wrap5">
    <div class="retweet-popup-body-wrap">
      <div class="retweet-popup-heading">
        <h3>Are you sure you want to delete this Tweet?</h3>
        <span><button class="close-retweet-popup"><i class="fa fa-times" aria-hidden="true"></i></button></span>
      </div>
       <div class="retweet-popup-inner-body">
        <div class="retweet-popup-inner-body-inner">
          <div class="retweet-popup-comment-wrap">
             <div class="retweet-popup-comment-head">
              <img src="<?php echo $tweet->profileImage;?>"/>
             </div>
             <div class="retweet-popup-comment-right-wrap">
               <div class="retweet-popup-comment-headline">
                <a><?php echo $tweet->screenName;?> </a><span>@<?php echo $tweet->username . ' ' . $tweet->postedOn;?></span>
               </div>
               <div class="retweet-popup-comment-body">
                 <?php echo $tweet->status . ' ' .$tweet->tweetImage;?>
               </div>
             </div>
          </div>
         </div>
      </div>
      <div class="retweet-popup-footer"> 
        <div class="retweet-popup-footer-right">
          <button class="cancel-it f-btn">Cancel</button><button class="delete-it" data-tweet="<?php echo $tweet->tweetID;?>" type="submit">Delete</button>
        </div>
      </div>
    </div>
  </div>
</div>
<?php }?>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?