我有一个iframe在我的页面从另一个子域。在这个iframe中,我有一个表单
<div id="main"></div>
<form id="fileForm" method="POST" action="https://othersub.samedomain.de/upload" enctype="multipart/form-data">
<input name="filename" type="file" id="filename"><br>
<input name="action" type="hidden" value="fileupload">
<a href="#" id="file-upload">upload</a>
</form>在我的JS中,我有:
$(document).ready(function() {
$("#file-upload").click(function(event){
event.preventDefault();
console.log("CLICK EVENT");
$("#fileForm").submit();
});
$("#fileForm").ajaxForm({
'target': '#main',
'dataType': 'json',
'type': 'POST',
'url': 'https://othersub.samedomain.de/upload',
beforeSubmit: function(){
/* show loading */
},
success: function(response, statusText, xhr, $form) {
/* do */
},
error: function(response, statusText, xhr, $form) {
/* do */
}
});
});所以我点击了upload按钮,我在IE中变成了一个错误:(拒绝访问) SCRIPT5
这就是这行代码(554):
submitFn.apply(form);或更多:
try {
form.submit();
} catch(err) {
// just in case form has element with name/id of 'submit'
var submitFn = document.createElement('form').submit;
submitFn.apply(form);
}在旧的IE中,当他必须使用iframe upload时,就会发生这种情况。我希望你能帮忙。
诚挚的问候
发布于 2013-12-13 01:06:30
输入文件有一个很大的问题,在IE上点击这个元素是必要的,如果你使用一个javascript来模拟这个点击,你会在提交后得到一个错误。尝试一下,将带有alpha 0和filter 0的输入文件放在一个假按钮上以选择该文件
示例
START HTML--------------------------------
< form ... >
< input type="file" id="ID_INPUTFILE" ....>
< a href="#" id="FAKE_BUTTON"> CHOSE YOU FILE < /a>
...
< /form >
< /html>
END HTML----------------------------------
START CSS---------------------------------
< style>
form { position:relative; }
#FAKE_BUTTON {
width: 200px;
height: 30px;
left: 10px;
top: 10px;
z-index:2;
}
#ID_INPUTFILE {
position: absolute;
width: 200px; /*WIDTH_OF_FAKE_BUTTON*/
height: 30px; /*HEIGHT_OF_FAKE_BUTTON*/
left: 10px; /*LEFT_POSITION_OF_FAKE_BUTTON */
top: 10px; /*TOP_POSITION_OF_FAKE_BUTTON */
z-index: 3; /*ALWAY OVER FAKE BUTTON */
opacity: 0.0; /*TO PUT INVISIBLE */
filter: alpha(opacity=0); /*TO PUT INVISIBLE fix ie */
}
< /style>
END CSS-----------------------------------https://stackoverflow.com/questions/18617704
复制相似问题