添加 return false 时,表单不会提交并刷新回同一页面
我之前曾发布过有关在确认提交之前触发对话框的文章。但是,不幸的是该文件现在没有提交。相反,它会保留在具有完全相同设置的同一页面上。我已经测试过,如果我删除submitform函数中的return false,文档提交将通过,但不会被“继续”按钮触发。因此,在这种情况下,我相信 return false 必须存在,但我如何确保我的文档将并且仅在单击“继续”后成功提交?我认为这纯粹是一个 javascript 问题,因为我的后端可以工作。
<script type="text/javascript">
function submitform(){
$("#dialog-submit").dialog("open");
return false
}
$("#dialog-submit").dialog({
autoOpen: false,
resizable: false,
height: 200,
width: 200,
modal: true,
buttons: {
"Proceed": function(){
//submit.
//tried document.submitform.submit(); does not work either
document.forms[0].submit();
$(this).dialog("close");
}
}
});
</script>
<form name="submitform" action="{{ request.path }}" method="post" enctype="multipart/form-data">
<input type="image" src="{{ MEDIA_URL }}images/submit.png" title="Submit Iteration" name="submitIter" onclick="return submitform();" value="{{ i.iter.key.id }}" width="25px"/>
</form>
i have previously posted about triggering a dialog box before confirming a submit. But, unfortunately the document now does not submit. Instead, it stays on the same page with the exact same setting. I have tested, if i remove the return false over at submitform function, the document submit will go through but it would not be triggered by "proceed" button. So in this case, i believe the return false has to be around but how can i ensure my document will and only submit successfully after clicking "proceed"? I think this is purely a javascript problem because my back end works.
<script type="text/javascript">
function submitform(){
$("#dialog-submit").dialog("open");
return false
}
$("#dialog-submit").dialog({
autoOpen: false,
resizable: false,
height: 200,
width: 200,
modal: true,
buttons: {
"Proceed": function(){
//submit.
//tried document.submitform.submit(); does not work either
document.forms[0].submit();
$(this).dialog("close");
}
}
});
</script>
<form name="submitform" action="{{ request.path }}" method="post" enctype="multipart/form-data">
<input type="image" src="{{ MEDIA_URL }}images/submit.png" title="Submit Iteration" name="submitIter" onclick="return submitform();" value="{{ i.iter.key.id }}" width="25px"/>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试将代码编写为 unobtrusive javascript。
这是一个用于修复的 jsfiddle 示例。
You should try writing your code as unobtrusive javascript.
Here's an example on jsfiddle for a fix.