2012-05-07 37 views
0

我无法获得两个变量来在确认窗口上按下按钮后使用ajax和jquery。我可以让每个变量单独显示,但是当我尝试同时发布两个变量时,它将无法工作。通过jQuery和ajax发布两个变量

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

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? 
    } 
} 
+0

http://api.jquery.com/jQuery.post/查看示例。 –

回答

3

你的文章的变量应该全部连接在一起。

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

你可以选择使用对象

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

真棒,完美工作。一旦9分钟的限制允许我,我会尽快接受你的回答! – user1104854

+0

只要你的php脚本是执行删除查询的脚本,那么应该没有问题。使用服务器上发生的删除代码更新您的代码,我将确保没有任何东西:) – Bryan

0

没有eqaul标志需要!像这样使用它

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

Downvoter,请发表评论吗? – Shyju

+0

这不是我。但是,我仍然试图按照你的建议去做,但它不起作用。 – user1104854

+0

@ user1104854:你是否收到任何脚本错误? – Shyju