douzi0609 2018-10-11 05:06
浏览 107

ajax成功后如何将div改为另一个?

<script>
    $(document).ready(function(){
       $(".add_friend").click(function(){
           f_id = this.id;
           user_id = <?php echo $_SESSION['user_id']; ?>;
           $.ajax({
              type:"POST",
              data:{"f_id":f_id,"user_id":user_id},
              url:"request_send.php",
              success:function(data){
                  $("#add").css("display","none");
                  $(".friend").css("display","block");
              }
           });
       });
    });
</script>

<div class="profile_btnn" id="add" style="display:block;">
    <button type="submit" name="add_friend" id="<?php echo $row_add['user_id']; ?>" class="btnplus add_friend"><i class="fa fa-plus"></i>&nbsp;Add Friend</button>
</div>
<div class="friend" style="display:none;">
    <div class="profile_btnn set_btn">
        <button type="submit" name="req_sent" id="<?php echo $row_req['f_id']; ?>" class="btnplus req_sent"><i class="fa fa-plus"></i>&nbsp;Request Sent</button>
    </div>
</div>

In this code. I want to change div i.e. id="add" with class="friend" after ajax success. Now, What happens when I click on add_friend it works successfully and change id="add" with class="friend". But the problem is when I refresh the page it again show me add friend. So, How can I fix this issue? Please help me.

Thank You

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算