0

在按下确认窗口上的按钮时,我无法使用 ajax 和 jquery 获取两个变量。我可以让任一变量单独显示,但是当我尝试同时发布两个变量时,它不起作用。

编辑 - 问题已解决。没有包含我需要的文件。我的错!

echo '<input type="button" value="Delete" onclick="deleteSomething(\'' . $replyID .'\', \'' .$tableName. '\',\'' .$replyBy. '\')" />';
?>
<script type="text/javascript">

function deleteSomething(replyID, tableName, replyBy)
{
if (!confirm("Are you sure?"))
    return false;
$.post('pageprocessing.php',"replyID=" + replyID + "&tableName=" + tableName + "&replyBy=" + replyBy, function(response) {
    alert(response);
});
}

这是我在 pageprocessing.php 上的脚本。我正确发布的所有三个值都回显,我只是无法弄清楚为什么它们没有被删除。

if(isset($_POST['replyID']) && isset($_POST['tableName']) && isset($_POST['replyBy'])){

    if($_POST['tableName'] == "replies" && $_POST['replyBy'] == $userid){
        echo $replyID = $_POST['replyID']; //echoing variables to make sure the page gets this far
        echo $replyBy = $_POST['replyBy'];
        echo $tableName = $_POST['tableName'];
        mysql_query("delete from replies where repliesID = $replyID "); //I can type this query into terminal and it deletes. Why won't it delete from here?
    }
}
4

2 回答 2

3

您帖子的变量都应该连接起来。

$.post('pageprocessing.php',"replyID=" + replyID + "&tableName=" + tableName, function(response) {
    alert(response);
});

您也可以使用对象

$.post('pageprocessing.php',{
    replyID     : replyID, 
    tableName   : tableName
}, function(response) {
    alert(response);
});
于 2012-05-07T01:06:52.640 回答
0

不需要等号!像这样使用它

$.post('pageprocessing.php',{ replyID : replyID, tableName :  tableName}, function(response) {
    alert(response);
});
于 2012-05-07T01:10:50.440 回答