简体   繁体   English

JavaScript表单提交等到完成

[英]Javascript form submit waiting till finishes

I have a form with upload 我有上载表格

<form action="../upload" method="post" id="upload_form" enctype="multipart/form-data" target="upload_frame" >
        <input name="file" type="file" />
    </form>

and it's submit using javascript form another form submit button 它是使用javascript表单提交的另一个表单提交按钮

function upload(){
    var uploadForm = document.getElementById('upload_form');

    uploadForm.submit();
    console.log('this should be called when the form finishes upload and respone is committed');

}

please tell if the example is not clear enough 请说明示例是否不够清楚

Add an onload handler to your iframe. 在您的iframe中添加onload处理程序。 It will be called after the server responds to the request. 服务器响应请求后将调用它。

For example: 例如:

var uploadFrame = document.getElementsByName('upload_frame')[0];

function handleResponseReceived() {
    console.log('this should be called when the form finishes upload and respone is committed');
}

if (uploadFrame.addEventListener) {
    uploadFrame.addEventListener('load', handleResponseReceived, false);
}
else {
    uploadFrame.attachEvent('onload', handleResponseReceived);
}

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

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