我无法获得两个变量来在确认窗口上按下按钮后使用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?
}
}
http://api.jquery.com/jQuery.post/查看示例。 –