admin管理员组

文章数量:1428340

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

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

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

}

please tell if the example is not clear enough

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

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

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

}

please tell if the example is not clear enough

Share Improve this question asked Jul 7, 2013 at 13:35 Mohamed Wagdy KhorshidMohamed Wagdy Khorshid 5574 gold badges15 silver badges32 bronze badges 1
  • @Yve I understood it as "I want to know when the server has received the request and responded". In other words, it looks like the OP is looking for a way to determine when the file has been sent to the server by checking for a response client-side. – Ray Nicholus Commented Jul 7, 2013 at 14:08
Add a ment  | 

1 Answer 1

Reset to default 3

Add an onload handler to your iframe. 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 mitted');
}

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

本文标签: htmlJavascript form submit waiting till finishesStack Overflow