开发者

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

Would you be able to say something like:

document.DataForm.submit();    //and foll开发者_如何学编程owing 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 (i.e. like GWT) become very powerful allies for managing your workflow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜