2012-05-07 39 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