Javascript表单提交等待完成



我有一个带有上传的表单

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

它使用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');
}

请说明示例是否不够清楚

在iframe中添加一个onload处理程序。它将在服务器响应请求后被调用。

例如:

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);
}

最新更新