您根本没有发出 POST 请求
从您的一条评论中(确认消息已更改为简洁):
<script language="javascript">
<!-- Confirm Dialog Box for deletion -->
function ConfirmChoice() {
answer = confirm("Are you sure?")
if (answer !=0) {
location = "recipe7.php"
}
}
</script>
假设这location
意味着document.location
:这意味着考虑到它在问题中的使用方式,一旦用户点击表单中的任何内容,只会发生以下两种情况之一:
工作解决方案
<script language="javascript">
function ConfirmChoice() {
return confirm("Are you sure?");
}
</script>
<form action='recipe7.php' method='post' onsubmit='return ConfirmChoice();' >
<input type='hidden' name='delete_dish' value='" . $row['dishname'] . "'>
<input type='image' src='images/delete2.png' alt='Submit' name='delete2' value='delete2'>
</form>
这两个区别是:
- 使表单提交到它应该提交的地方
- 使用 onsubmit 提示用户,而不是点击。
如果表单 onsubmit 回调返回 false - 提交表单被中止。
附加点
javascript中的注释
形式为:
// this is a comment
/* this is a
multiline
comment */
在 javascript 块中使用 html 注释 ( <!-- asdf -->
) 无效。
默认情况下不用 js 也能正常工作。
编写仅在不需要时启用 js 的功能 - 只会增加复杂性。而是让它在没有 js 的情况下工作 - 然后在之后添加你想要的任何 js 功能(最低限度)。
坚持这个原则会有两个后果:
- js逻辑更简单(因为少了)
- 如果有 js 错误,事情仍然有效。