我正在尝试设置一个确认框以在 php 页面上使用 javascript/jquery 删除消息。在 javascript 函数中正确设置了变量,但现在我无法让函数正确发布到页面。
我在头中包含以下内容
<script src="http://code.jquery.com/jquery-latest.js"></script>
现在是代码。
//displays a list of messages w/ button to delete
if(mysql_real_escape_string($_GET['msg'] == "msgDetail")){
$msg->messageDetail($msgID);
$action = "delete";
$msgID = mysql_real_escape_string($_GET['msgID']);
//display a delete button that sends variables to javascript function
echo '<td>'.'<input type="button" value="Delete Message" name = "deleteMessage" onclick="deleteMessage(\'' . $msgID .'\', \'' .$action. '\',\'' .$userid. '\')" />'.'</td>';
}
?>
//javascript function for confirmation to delete message
<script type="text/javascript">
function deleteMessage(msgID, action, userid){
//document.write(msgID + action + userid) values are correctly showing up here when uncommented
if (!confirm("Are you sure?"))
return false;
$.post('messages.php',"msgID=" + msgID + "&action=" + action + "&user=" + userid, function(response) {
//window.location.reload()
});
}
</script>
<?
//check to see if the values have been posted
if($_POST['action']) == "delete"){
echo "success!";
....more code
}
如您所见,我正在尝试将变量发布到messages.php,但是当我检查是否发布了一个变量时,什么也没有发生。