通过jquery和ajax发布两个变量

posting two variables through jquery and ajax

本文关键字:布两个 变量 ajax jquery 通过      更新时间:2023-09-26

我在按下确认窗口上的按钮时无法使用 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);
});
}

这是我关于页面处理的脚本.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?
    }
}

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

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

您也可以使用对象

$.post('pageprocessing.php',{
    replyID     : replyID, 
    tableName   : tableName
}, function(response) {
    alert(response);
});

不需要 eqaul 符号!像这样使用它

$.post('pageprocessing.php',{ replyID : replyID, tableName :  tableName}, function(response) {
    alert(response);
});