2013-07-07 71 views
1

我有上傳的形式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'); 

} 

,請告訴我們,如果例子是不夠

明確提出
+0

@Yve我理解爲「我要當服務器收到請求,並回答知道」。換句話說,它看起來像OP正在尋找一種方法來確定文件何時被髮送到服務器,通過檢查響應客戶端。 –

回答

2

爲你的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); 
} 
+0

這是被投票的任何理由? –

+0

不是我自己,但我沒有看到iframe – mishik

+0

看看錶單目標。顯然有一個iframe。 –