Bug extracting content from an Iframe using JQuery
I'm uploading some files in the same page using the Iframe technique. 开发者_如何转开发I'm extracting the content from the IFrame. Everything is ok for the first submission, but when I make a second submission I got an extra line in the console log, and for the third submission I got 2 extra lines...
What I got in the Firebug console is:
-
name_1
+
-
name_2
+
name_2
+
What is my error?
<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>
I believe you are adding an additional load handler every time you submit the form. Try removing this:
$('#upload_target').load(function()
{
console.log ( $('#upload_target').contents().find('#response').html() );
console.log ( "+" );
});
from the submit handler and just put it outside the submit handler.
精彩评论