现在我有这个:

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


它是带有链接的图标,单击该链接可以删除评论。

现在,它进入misc/removeWallComment.php并回显“注释已删除”。但是,我想将其与我当前的网站集成在一起,因此您无需转到另一个页面即可删除该commehnt。有了这个,我想到了对removeWallComment.php使用ajax调用。

现在,如您在链接上看到的,它需要三个变量,分别为iduIDBuID,我想将其发送为POST,而不是GET,因此用户无法在地址栏中看到变量。成功的话,应该警惕。

我怎样才能做到这一点?

最佳答案

为了使这个问题有一个答案:

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();
});


使用GETPOST都没有关系,如果使用的是Ajax,则用户将永远不会在地址栏中看到三个id。但是,必须以某种方式获取三个id,因此在这种情况下,我们正在为其解析href值(三个id必须存储在某个位置,最好存储在元素本身上,以便于检索。)出于安全原因想要隐藏id,这不是最好的方法)。

10-07 19:51
查看更多