Is form submit synchronous or async?

后端 未结 3 1382
轮回少年
轮回少年 2021-01-11 14:51

I am just wondering if the document.myForm.submit() is a synchronous call, that will block until finished... or if it is async and will continue to execute without waiting f

相关标签:
3条回答
  • 2021-01-11 15:20

    It's an asynchronous call.

    However, at some point, the new page will load, and your page will be destroyed.

    0 讨论(0)
  • 2021-01-11 15:24

    The browser seems to continue to execute javascript immediately after submitting a form. In this jsFiddle example, the log statement is printed before the form is submitted.

    Markup

    <form action="foobar"></form>
    <button id="submitBtn">Submit</button>
    

    Javascript

    var button = document.getElementById('submitBtn');
    button.onclick = function() {
        document.forms[0].submit();
        console.log('after submitting');
    };
    
    0 讨论(0)
  • 2021-01-11 15:38

    I had a jsp page that a page-reloading function follows right after a submit method. Then I faced 'unexpected end of part' error immediately. Submit() must be asynchronous.

    0 讨论(0)
提交回复
热议问题