跟随和取消关注不在循环Codeiginter中工作

时间:2016-04-27 03:57:04

标签: ajax codeigniter

我有单页用户列表

在那里我想在同一页面中使用跟随和取消关注

如果我跟随它,只需更改div颜色并存储到数据库中。

在我为第一位用户工作的编码中,但不适用于第二,第三,......等用户..

这是我的查看代码

<div class="gird12" id="followsuccess">
                <div class="team-mbr1">
                <?php foreach($userList as $user) { ?>
                    <div class="t-11" id="<?php echo $user->id; ?>">
                    <a href="<?php echo base_url($user->pagename); ?>" >
                        <div class="t-11-img">
                            <?php if($user->image != ''){ echo '<img src="'.$user->image.'" />'; }  ?>
                            <?php if($user->image == ''){ echo '<img src='.base_url('images/sample5.jpg').' />'; }  ?>
                        </div>
                    </a>
                        <input type="hidden" name="id" id="id" value="<?php echo $user->id; ?>" />
                        <?php
                        if($login_status == 1)
                        {
                        $followers = $this->db->where(array('user_id' => $userId , 'follower_id' => $user->id, 'follow_status' => 1))->get('sr_follow')->result();

                        if(count($followers) != ''){   ?>
                        <a id="userunfollow">
                        <div class="btn-11">
                            <button class="button button2" id="userunfollow">Following <?php echo $user->firstname; ?></button>
                        </div>
                        </a>
                        <?php } ?>


                        <?php if(count($followers) == ''){   ?>
                        <a id="userfollow">
                        <div class="btn-11">
                            <button class="button button1" id="userfollow">Follow <?php echo $user->firstname; ?></button>
                        </div>
                        </a>
                        <?php }  }  ?>
                     </div>
                  <?php }  ?>
                </div>
             </div>

我的 Ajax

    // ****** ****** Follow ****** ****** //
$("#userfollow").click(function(){
            var id = $('#id').val();  
            var url = $('#url').val();  
            var Data= 'id='+id;

        $.ajax({
            type: "POST",
            url: url+"pages/userList/followinguser",
            data: Data, 
            cache: false,
            success: function(result){
            // This replace the retrieved data to the div after the setTimeOut function
            $('div#followsuccess').html(result);
            }
        });

});

// ***** ***** UnFollow ****** ****** //
$("#userunfollow").click(function(){
        var id = $('#id').val();  
        var url = $('#url').val();  
        var Data= 'id='+id;

    $.ajax({
        type: "POST",
        url: url+"pages/userList/unfollowinguser",
        data: Data, 
        cache: false,
        success: function(result){
        // This replace the retrieved data to the div after the setTimeOut function
        $('div#followsuccess').html(result);
        }
    });
});

1 个答案:

答案 0 :(得分:0)

将ID更改为onclick功能

Ajax代码

// ****** ****** Follow in list of creators page ****** ****** //
function userfollow(id,url)
{
    alert(id);
    alert("follow");
    var Data= 'id='+id;
    $.ajax({
        type: "POST",
        url:  url+"pages/userList/followinguser",
        data: Data, 
        cache: false,
        success: function(result){
            // This replace the retrieved data to the div after the setTimeOut function
            $('div#followsuccess').html(result);
        }
    }); 
}
// ****** ****** Follow in list of creators page ****** ****** //

// ****** ****** UNFollow in list of creators page ****** ****** //
function userunfollow(id,url)
{
    alert(id);
    alert("unfollow");
    var Data= 'id='+id; 
    $.ajax({
        type: "POST",
        url: url+"pages/userList/unfollowinguser",
        data: Data, 
        cache: false,
        success: function(result){
            // This replace the retrieved data to the div after the setTimeOut function
            $('div#followsuccess').html(result);
        }
    }); 
 }
// ****** ****** UNFollow in list of creators page ****** ****** //