如何从 java 脚本调用 xforms 提交
当我单击浏览器关闭按钮时,我也想提交我的 xform。
为了实现这一点,我编写了主体卸载函数,该函数在浏览器关闭时调用。
现在,我想从这个java脚本函数调用xforms提交,
<xhtml:body class="MainBODY" onunload="browserClose()">
请建议一些方法来执行相同的操作。
I would like to submit my xform when i click on the browser close button also.
To achieve that i have written body unload function which is called when the browser is closed.
Now from this java script function i want to call the xforms submit
<xhtml:body class="MainBODY" onunload="browserClose()">
Please suggest some way to do the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是(或者不取决于您如何看待它),您无法在
onbeforeunload
中可靠地调用服务(发出 Ajax 请求)。当用户离开您的页面时,您可以运行一些 JavaScript,并且该 JavaScript 可以发出 Ajax 请求,但浏览器不会等待响应,并且该请求甚至有可能无法到达服务器。因此,您能做的最好的事情就是向用户发出警报,这使他们有机会不离开表单,例如保存他们刚刚输入的数据,否则可能会丢失。请参阅如何提醒用户离开表单而不保存以获取更多信息。
Unfortunately (or not depending on how you look at it), you can't reliably call a service (make an Ajax request) in
onbeforeunload
. When the user navigates away from your page, you can run some JavaScript, and that JavaScript can issue an Ajax request, but the browser won't wait for the response and there is a chance that the request doesn't even make it to the server.So the best you can do is to issue an alert to users, which gives them a chance not to leave the form, for instance to save data they just entered and that otherwise might be lost. See how to alert users leaving a form without saving for more on this.