views:

61

answers:

2

Right now I have this:

echo "<a href='misc/removeWallComment.php?id=" . 
    $displayWall['id'] . "&uID" . $displayWall['uID'] . "&BuID" . 
    $displayWall['BuID'] . "' title='ta bort inlägg'> 
    <span class='removeWallComment'></span> </a>";

Its an icon with a link that removes the comment when you click.

Now, it goes to misc/removeWallComment.php and echo out "comment removed". But I would like to integrate it with my current site, so you don't go to another page to delete the commehnt. With this I thought of using an ajax call to removeWallComment.php.

Now as you see on the link it requires three variables, id, uID and BuID, and I want to send it POST, not GET so the user can't see the variables in address bar. On success it should just alert ok.

How can I do this?

A: 

alright, i actually just recently made something like that, i am working on making a social networking site and just figured out how to ge tsomething like that to work, so let me get this clear though, you want to be able to click a post and it goes away, while also echoing out comment removed? Simple! Let me know if this is what you want and i will work on posting it here ok.

Michael
A: 

Just so that this question will have an answer:

var links = $('.removeWallComment').parent();

links.click(function(event) {
    // Parse out the ids
    var data = this.href.substring('?').split('&');

    var id = data[0].substring(data[0].indexOf('=') + 1);
    var uid = data[1].substring(data[1].indexOf('=') + 1);
    var BuID = data[2].substring(data[2].indexOf('=') + 1);

    $.post('misc/removeWallComment.php', {
        'id': id,
        'uid': uid,
        'BuID': BuID
    }, function(data){
        // Success!
        alert('OK');
    });

    event.preventDefault();
});

It doesn't matter if you use GET or POST, if you're using ajax you're user will never see the three ids in the address bar. The three ids, however, must be gotten somehow, so in this case we are parsing the href value for them (the three id must be stored somewhere, preferably on the element itself for easy retrieval. If you want to hide the ids for security reasons this isn't the best way to do it).

Yi Jiang