这是我的确认框代码。当我按OK
时,它应该调用删除功能。当我按Cancel
时,它应该返回主页,但即使我选择Cancel
,文件也会被删除。这是我的代码。有什么问题?
var response = confirm ("Are you sure you want to permanently delete this user?");
if (response)
{
<% String userName =request.getParameter("userName");
del.del(userName);
%>
window.location.href='adminHome.jsp';
}
else
{
window.location.href='adminHome.jsp';
}
答案 0 :(得分:5)
此代码:
<% String userName =request.getParameter("userName");
del.del(userName);%>
在页面被发送到浏览器之前,在您的服务器上运行,因此用户在您到达confirm()
之前已经离开。
您必须通过简单发布表单或通过ajax引入显式的新HTTP请求,并在服务器上处理。只有在您的确认返回true
时才会触发该请求。