我無法獲得兩個變量來在確認窗口上按下按鈕後使用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/查看示例。 –