3

我一直试图得到这个年龄

我正在建立一个有活动墙的网站。除了喜欢和不同的按钮外,我的所有东西都在工作。我让他们目前只显示我喜欢或不喜欢的文本框

<a href='#' onclick='like()'>Like</a>

或者

<a href='#' onclick='unlike()'>Unlike</a>

现在这些调用这些脚本

<script>
    function like()
    {
        alert("I like");
        document.getElementById("p1").innerHTML="<a href='#' onclick='unlike();'>Unlike</a> | 1 Life<hr/>";
    }
    function unlike()
    {
        alert("Dont like anymore");
        document.getElementById("p1").innerHTML="<a href='#' onclick='like();'>Like</a> | 0 Lifes<hr/>";
    }
</script>

我有一个连接到数据库并添加或删除我知道有效的 php 脚本。我不需要向 javascript 返回任何内容,但是如何调用给出 postID 和用户名的 php 脚本?


好的,所以使用它我对其进行了一些修改。但它仍然不起作用:S

==LikeUnlink.php==

<?php
include 'phpScripts/OpenConnection.php';    
$mode = $_GET['mode'];
$username = $_GET['username'];
$postID = $_GET['LikeID'];
echo $username."<br/>";
echo $mode."<br/>";
echo $postID."<br/>";
if($mode == 0)
{
    $query = "INSERT INTO tbl1Ups (Username, ActivityID) VALUES ('$username', $postID)";    
}
else
{
    $query = "DELETE FROM `tbl1Ups` WHERE Username='$username' AND ActivityID=$postID";
}
$result = mysql_query($query) or die(mysql_error());

==MembersHome.php==

<script type="text/javascript">
function process(LikeId, Username, currentLikes, likeUnlike)
{
//your validation code
    $.ajax(
    {
    type: 'GET',
        url: LikeUnlike.php, //file where like unlike status change in database
    data:{like:LikeId, username:Username, mode:likeUnlike},
    success: function(data)
        {
            alert('It Works');
    }
    } );
}
</script>

==点赞链接==

<a href='Javascript:void(0)' onclick='process(".$row['ID'].", \"".$username."\", ".$likes.", 0);'>$linkText</a>
4

1 回答 1

3

试试这个

<script type="text/javascript">
function process(LikeId) { 
//your validation code
$.ajax( {
        type: 'POST',
        url: LikeUnlike.php, //file where like unlike status change in database
        data:{like:LikeId},
        success: function(data) {
            //code you want to do after successfull process
        }
    } );
}
</script>

在 html 中进行更改

<a href='Javascript:void(0)' onclick='process(1)'>Like</a>
<a href='Javascript:void(0)' onclick='process(0)'>Unlike</a>
于 2013-05-01T07:00:59.723 回答