1

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

4
  • If you look at the html source of that page, do the values get set correctly? Commented Aug 28, 2010 at 14:16
  • Also, do you need all the hidden inputs? Why not pass the values directly to the function via parameters? Commented Aug 28, 2010 at 14:21
  • How? I only know this method, yea, the uID is the friend1 and bID is friend2 and fID is the id of the row Commented Aug 28, 2010 at 14:24
  • I am writing a answer suggestion, but can explain which values you want to pass to your javascript function? fID -> $showW["id"]; bID -> $showW["bID"]; and uID -> $sid; ?? Commented Aug 28, 2010 at 14:36

2 Answers 2

1

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"]; ?>
Sign up to request clarification or add additional context in comments.

Comments

0

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; ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.