tags:

views:

43

answers:

2

In my friends page, when you accept a user, it sends a ajax call:

function MeYouFriendNB(confirm){
 var c = confirm ? 'confirm' : 'ignore';
var fID = $('.fID').val();

    $.ajax({ 
       type: "POST",
       url: "misc/AddFriend.php",
    data: {
    mode: 'ajax',
        friend: c,
    uID : $('#uID'+fID).val(),
    fID : $('#fID'+fID).val(),
        bID : $('#bID'+fID).val()
    },
       success: function(msg){
$('#friend'+fID).slideUp('slow');
$('#Friendlist').prepend(msg);
 $('#theNewFriend').slideDown('slow');
        }
     });
}

On each friend request, there's a link to the function:

<?php
while($showW = mysql_fetch_array($friendsWaiting)){
echo "<div id='friend".$showW['id']."' style='position: relative; background: #3a5f6e;'>";
?>
        <input type="hidden" name="fID" class="fID" value="<? echo $sInfo["id"]; ?>">
    <input type="hidden" name="uID" id="uID<? echo $showW["id"]; ?>" value="<? echo $sid; ?>">
<input type="hidden" name="fID" id="fID<? echo $showW["id"]; ?>" value="<? echo $showW["id"]; ?>">
<input type="hidden" name="bID" id="bID<? echo $showW["id"]; ?>" value="<? echo $showW["bID"]; ?>">

    <?php
echo "<div style='position: absolute; top: 15px; right: 105px;'>
<a href='javascript:void(0);' onclick='MeYouFriendNB(true);' style=' margin-right: 45px; color: #FFF;'>Bekräfta</a>
 <a href='javascript:void(0);' onclick='MeYouFriendNB(false);' style='color: #ccc;'>Ignorera</a></div>";
}
?>

But everytime it sends the ajax call, it gives same fID, bID and uID, to every friendrequest. So e.g if i have 5 friend request, them all have same fID, uID and bID.

As you can see i tried to make the bID and uID and fID´s id unique by adding <? echo $showW["id"]; ?> to the id´s fID, uID and bID, and in the function, i made a var fID that checks class .fID for the id, that they all have... but this didnt work out, it still send the same ids to the ajax call

Hope you can help me

+1  A: 

You are not opening the PHP script tags correctly. If you need short tags you can use

<?=$sInfo["id"]; ?>

Of course you should avoid that if possible. Else it should be

<?php echo $sInfo["id"]; ?>
Yi Jiang
Wasnt the case..
Karem
A: 

I would do it like this: (not sure if this solves your problem though)

Javascript:

function MeYouFriendNB(confirm, uID, fID, bID){
    var c = confirm ? 'confirm' : 'ignore';

    $.ajax({ 
        type: "POST",
        url: "misc/AddFriend.php",
        data: {
            mode: 'ajax',
            friend: c,
            uID: uID,
            fID: fID,
            bID: bID
        },
        success: function(msg){
            $('#friend'+fID).slideUp('slow');
            $('#Friendlist').prepend(msg);
            $('#theNewFriend').slideDown('slow');
        }
    });
}

PHP:

<?php while($showW = mysql_fetch_array($friendsWaiting)): ?>
    <div id="friend<?php echo $showW['id']; ?>" style="position: relative; background: #3a5f6e;">
        <div style="position: absolute; top: 15px; right: 105px;">
            <a href="javascript:void(0);" onclick="MeYouFriendNB(true, <?php echo $showW["id"]; ?>, <?php echo $showW["bID"]; ?>, <?php echo $sid; ?>);" style="margin-right: 45px; color: #FFF;">Bekräfta</a>
            <a href="javascript:void(0);" onclick="MeYouFriendNB(false, <?php echo $showW["id"]; ?>, <?php echo $showW["bID"]; ?>, <?php echo $sid; ?>);" style="color: #ccc;">Ignorera</a>
        </div>
    </div>
<?php endwhile; ?>
captaintokyo
Niceone, thanks!
Karem
You're welcome!
captaintokyo