2011-05-23 82 views
0

我使用Iframe技術在同一頁面上傳了一些文件。我從IFrame中提取內容。第一次提交的時候一切正常,但是當我第二次提交時,我在控制檯日誌中得到了一個額外的行,第三次提交時我得到了兩個額外的行...使用JQuery從Iframe中提取內容的問題

我在Firebug控制檯中得到的是:

- 
name_1 
+ 
- 
name_2 
+ 
name_2 
+ 

我的錯誤是什麼?

<script> 
window.onload=init; 

function init() { 
    $('#file_upload_form').submit(function() 
    { 
    document.getElementById('file_upload_form').target = 'upload_target'; 

    $('#upload_target').load(function() 
    { 
     console.log ($('#upload_target').contents().find('#response').html()); 
     console.log ("+");    
    }); 
    console.log ("_"); 

    }); 
} 

</script> 
+0

什麼是'iframe技術'? – Neal 2011-05-23 21:11:45

+0

這一個http://www.openjs.com/articles/ajax/ajax_file_upload/ – earlyriser 2011-05-23 22:10:52

回答

0

我相信您每次提交表單時都會添加一個附加的載入處理程序。嘗試刪除此:

$('#upload_target').load(function() 
    { 
     console.log ($('#upload_target').contents().find('#response').html()); 
     console.log ("+");    
    }); 

從提交處理程序,只是把它放在提交處理程序之外。

+0

我做到了,但我現在不知道如何從iframe中提取信息。我把下面的代碼。這是你建議的嗎? earlyriser 2011-05-23 22:11:42

+0

把它放在init裏面但在提交之外。 – 2011-05-23 23:21:43

+0

非常感謝!有用 – earlyriser 2011-05-24 20:15:15