简体   繁体   English

在浏览器中提交POST后重新加载页面

[英]Reloading the page after submitting POST in a browser

I have an XPage which uses JQuery dialog where I have a button (inside a plain div nothing with JQuery) which creates a new backend "part" when triggered. 我有一个使用JQuery对话框的XPage,其中有一个按钮(在普通div中没有​​JQuery),当触发时它会创建一个新的后端“部件”。 On the other hand, on the client-side there's validation(which checks that all fields aren't empty). 另一方面,在客户端进行验证(检查所有字段都不为空)。 If client-side validation succeed, server-side executes back-end code and new "part" gets created. 如果客户端验证成功,则服务器端将执行后端代码,并创建新的“部件”。 The problem I've encountered is when new part gets created, if I hit F5 button, browser offers me to repeat the request. 我遇到的问题是创建新零件时,如果我按F5键,浏览器会提示我重复该请求。 If the user clicks "Yes", new part(which is the duplicate of the last one in form) gets created. 如果用户单击“是”,则将创建新零件(与表单中最后一个零件重复)。 How do I prevent it? 我该如何预防?

<xp:button id="save_part_btn"
                        value="+Add part" style="float:right;">
                        <xp:eventHandler event="onclick" submit="true"
                            refreshMode="complete">
                        <xp:this.action><![CDATA[#{javascript:
var estdoc:NotesDocument=database.getDocumentByUNID(doc_source.getDocument().getParentDocumentUNID())
var estPartdoc:NotesDocument=estdoc.getParentDatabase().createDocument()

estPartdoc.replaceItemValue('Form','Estimate_Cost_Part')
estPartdoc.replaceItemValue('Predoc',estdoc.getUniversalID())
estPartdoc.replaceItemValue('$OSN_IsSaved','1')

estPartdoc.replaceItemValue('Title', getComponent('input_part_title').getValue())
estPartdoc.replaceItemValue('TSNB_Title',getComponent('input_tsnb_title').getValue())
estPartdoc.replaceItemValue('TSNB_All',getComponent('input_tsnb_all').getValue())
estPartdoc.replaceItemValue('TSNB_Build_Work',getComponent('input_tsnb_build_work').getValue())
estPartdoc.replaceItemValue('TSNB_Equipment',getComponent('input_tsnb_equipment').getValue())
estPartdoc.replaceItemValue('TSNB_Other_Costs',getComponent('input_tsnb_other_costs').getValue())
estPartdoc.replaceItemValue('TSNB_PIR',getComponent('input_tsnb_pir').getValue())
estPartdoc.replaceItemValue('TSNB_Return',getComponent('input_tsnb_return').getValue())

estPartdoc.replaceItemValue('Current_Title',getComponent('input_current_title').getValue())
estPartdoc.replaceItemValue('Current_All',getComponent('input_current_all').getValue())
estPartdoc.replaceItemValue('Current_Build_Work',getComponent('input_current_build_work').getValue())
estPartdoc.replaceItemValue('Current_Equipment',getComponent('input_current_equipment').getValue())
estPartdoc.replaceItemValue('Current_Other_Costs',getComponent('input_current_other_costs').getValue())
estPartdoc.replaceItemValue('Current_PIR',getComponent('input_current_pir').getValue())
estPartdoc.replaceItemValue('Current_NDS',getComponent('input_current_nds').getValue())
estPartdoc.replaceItemValue('Current_Return',getComponent('input_current_return').getValue())

//var estPartOdoc=new OsnovaUI_document(estPartdoc)
//estPartOdoc.makeDependent(estdoc)

print('new part created with id:'+estPartdoc)
estPartdoc.makeResponse(estdoc)
estPartdoc.save() 


var ag:NotesAgent=database.getAgent('User_CalculateEstimateCost')
ag.runOnServer(doc_source.getDocument().getNoteID())

}]]></xp:this.action>

Server-side code, nothing really special. 服务器端代码,没有什么特别的。 On submit = "true" I return true if validation succeeds, false if fails submit = "true"如果验证成功,则返回true;如果失败,则返回false

You need to implement the POST-Redirect-GET pattern. 您需要实现POST-Redirect-GET模式。 Here's an example (from 2010): XPages: Avoid saving duplicate documents on browser refresh . 下面是一个示例(从2010年开始): XPages:避免在浏览器刷新时保存重复的文档

The crucial part is to include a redirect at the end of your server-side logic. 关键部分是在服务器端逻辑的末尾包括重定向。 Here's a simple example: 这是一个简单的例子:

context.redirectToPage(view.getPageName());

In your case the redirect needs to reopen the document so do this: 在您的情况下,重定向需要重新打开文档,因此请执行以下操作:

context.redirectToPage(view.getPageName()+ "?OpenXpage&documentId="+doc_source.getNoteID());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM