I created this jQuery + html piece to do the following:
There is a placeholder image that the user can click, which opens a file selection dialog box. After selecting the file, the corresponding multi-part form is uploaded to the server. I am trying to simulate AJAX behavior to load this file, so I also use an invisible iframe to get the server response.
Let me introduce the code first, so it would be easier to explain the problem.
jQuery("#myInput").change(function () { // Submit form upon file selection
// alert("myInput.val() = " + $('#myInput').val()); // alert 1
$('#form1').submit();
// alert("myInput.val() = " + $('#myInput').val()); // alert 2
});
<form id="form1" action="/do_upload.php" method="post" enctype="multipart/form-data" target="target_frame">
<input id="myInput" type="file" name="userfile" /><br>
</form>
<img src="/img/placeholder.png" onclick="$('#myInput').click();" >
<iframe id="target_frame" name="target_frame" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
Chrome/FF/Safari. (, , ": hidden" "myInput". , -, ). IE 9 10 : , "alert 1", "alert 2", , , "myInput" .
, ! , IE, :)