【发布时间】:2011-02-17 15:20:02
【问题描述】:
我在尝试通过 iFrame 发布表单时遇到此错误。在 IE 8 中。在 FF 和 Opera 中运行良好。
问题的简短版本是:我有一个复杂的表单,我使用 JavaScript 将其转换为复杂的 json 对象,然后将其转换为 json 字符串。我在页面中添加了一个表单,其中包含 json 字符串的隐藏字段,并克隆了文件控件并提交了带有 iframe 目标的表单。
这是我的测试代码:
<div id="testingFormHolder">
<form id="IFrameSubmitForm">
<input type="text" id='testText' name='testText' />
<input type="file" id='testFile23' name='testFile' cfid="23" />
<input type="file" id='testFile24' name='testFile' cfid="24" />
<input type="button" id='testSubmit' name='testSubmit' />
</form>
</div>
<div id="TempFormHolder">
</div>
<div id="IFrameHolder" class="">
</div>
<script type="text/javascript">
$(function () {
$('#testSubmit').click(function () {
var fileControls = $('#testingFormHolder').find('input[type=file]');
var otherDataObject = { "field1": 'blah blah field 1', "field2": "field2" };
var iframe = $('<iframe name="theIFrame" id="theIFrame" class="" src="about:none" />');
var theFileNames = new Array();
var thefiles = $('#testingFormHolder').find('input[type=file]');
thefiles.each(function () {
theFileNames.push({ cfid: $(this).attr('cfid'), FileName: $(this).val() });
});
otherDataObject.fileNames = theFileNames;
var otherData = JSON.stringify(otherDataObject);
$('#IFrameHolder').empty().append(iframe);
var theForm = $('<form id="TempForm" name="TempForm">');
fileControls.each(function () {
theForm.append($(this).clone().attr('name', 'files').attr('id', $(this).attr('customFieldId')));
});
// theForm.append(fileControl.clone().attr('name', 'files').attr('id', 'file1'));
theForm.append($("<input type='text' id='model' name='model' value='" + otherData + "' />"));
theForm.attr('action', '<%= Url.Action(MVC.Temp.Actions.TestingFormSubmitThroughIFrame)%>');
theForm.attr('method', 'POST');
theForm.attr('enctype', 'multipart/form-data');
theForm.attr('encoding', 'multipart/form-data');
theForm.attr('target', 'theIFrame');
$('#TempFormHolder').empty().append(theForm);
theForm.submit();
// $('#theIFrame').load(function () {
// });
return false;
});
});
</script>
我正在使用 asp.net mvc。当我在寻找答案时,我遇到了一个关于混合 http 和 https 的页面,但我只是在本地主机上运行它。测试页地址为: http://localhost:60819/Temp/Testing/ 和 '' = "/Temp/TestingFormSubmitThroughIFrame"
编辑:将操作更改为完整地址而不是“/Temp/TestingFormSubmitThroughIFrame”并没有解决它。
感谢您的帮助!
编辑:很抱歉,我认为它复制了整个错误消息!完整的错误信息是:
“网页导航已取消” “你可以尝试什么: 重新输入地址。
"
当它尝试提交时出现在我的 iframe 中。它甚至没有尝试发帖。
【问题讨论】:
-
你问题的最后一部分很混乱。究竟是什么错误,何时发生等?
-
抱歉!复制/粘贴效果不如我。我已经添加了完整的消息(不多)
标签: javascript jquery forms iframe internet-explorer-8