简体   繁体   English

javascript:确认Submit()是否完成重新加载页面的代码

[英]javascript: code to confirm if submit() completed reloading the page

Would you be able to say something like: 您能否说出类似以下内容:

document.DataForm.submit();    //and following this

if (document.DataForm.submit().completed) {

console.log("page reload has been completed");

}

// I need to write a javascript code to confirm that submit() completed reloading the page.

Normally, this is done using an asynchronous request. 通常,这是使用异步请求完成的。

1) User clicks submit. 1)用户点击提交。

2) Form data gets submitted, page is still active. 2)提交表单数据,页面仍处于活动状态。

3) Once form data is submitted, server sends acknowledgement and error messages if any . 3)提交表单数据后,服务器将发送确认和错误消息(如果有)。

4) Now, your ".completed()" method's body code can run. 4)现在,您的“ .completed()”方法的主体代码可以运行了。

The thing to realize here is that, once you submit data in a form, a request is invoked and control is lost by the page. 在这里要实现的事情是,一旦您以表单提交数据,就将调用一个请求,并且页面将失去控制。

  • The best library I know of for this is in Java is GWT, which autogenerates javascript for you - it allows you to build statefull web applications which do these things under the hood, so the code looks pretty similar to what your wrote. 我所知道的最好的库是Java,它是GWT,它可以为您自动生成javascript-它使您可以构建有状态的Web应用程序,以在后台执行这些操作,因此代码看起来与您编写的代码非常相似。

  • Remember : The web is stateless. 记住:网络是无状态的。 Once you start adding state and monitors to your javascript, you are building a "rich" web app - and the various app frameworks out there (ie like GWT) become very powerful allies for managing your workflow. 一旦开始向JavaScript添加状态和监视程序,您将构建一个“丰富的” Web应用程序-各种应用程序框架(例如GWT)成为管理您的工作流的强大盟友。

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

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