简体   繁体   中英

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.

2) Form data gets submitted, page is still active.

3) Once form data is submitted, server sends acknowledgement and error messages if any .

4) Now, your ".completed()" method's body code can run.

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.

  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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