Javascript Iframe不会第二次呈现内容
我在主视图的Iframe中通过ajax渲染部分视图。它在本地运行良好,但在第一次发布其作品后第二次清除iframe主体 这是我的密码:Javascript Iframe不会第二次呈现内容,javascript,jquery,ajax,iframe,asp.net-mvc-5,Javascript,Jquery,Ajax,Iframe,Asp.net Mvc 5,我在主视图的Iframe中通过ajax渲染部分视图。它在本地运行良好,但在第一次发布其作品后第二次清除iframe主体 这是我的密码: $('#editFaxdialog').dialog({ autoOpen: false, title: 'Edit PDF', height: 'auto', width: '80%', position: ['top', 50], draggable: fal
$('#editFaxdialog').dialog({
autoOpen: false,
title: 'Edit PDF',
height: 'auto',
width: '80%',
position: ['top', 50],
draggable: false,
show: 'blind',
hide: 'blind',
modal: true,
open: function (event, ui) {
$.ajax({
url: '@Url.Action("EditPdf", "Fax")',
type: 'GET',
cache:false,
success: function(data){
var frameSet = document.getElementById("editFaxFrame");
var iframedoc = frameSet.document;
if (frameSet.contentDocument)
iframedoc = frameSet.contentDocument;
else if (frameSet.contentWindow)
iframedoc = frameSet.contentWindow.document;
if (iframedoc){
iframedoc.open();
iframedoc.writeln(data);
iframedoc.close();
}
},
error: function () {
window.location.href = '@Url.Action("Index","Error")';
}
});
},
close: function (event, ui) {
$("#editFaxFrame").attr("src", '');
}
});
在进行了大量的研发之后,我成功地将Settimeout()函数用于ajax,从而解决了这个问题
$('#editFaxdialog').dialog({
autoOpen: false,
title: 'Edit PDF',
height: 'auto',
width: '80%',
position: ['top', 50],
draggable: false,
show: 'blind',
hide: 'blind',
modal: true,
open: function (event, ui) {
$.ajax({
url: '@Url.Action("EditPdf", "Fax")',
type: 'GET',
cache:false,
success: function(data){
setTimeout(function () {
var frameSet = document.getElementById("editFaxFrame");
var iframedoc = frameSet.document;
if (frameSet.contentDocument)
iframedoc = frameSet.contentDocument;
else if (frameSet.contentWindow)
iframedoc = frameSet.contentWindow.document;
if (iframedoc){
iframedoc.open();
iframedoc.writeln(data);
iframedoc.close();
}
},400);
},
error: function () {
window.location.href = '@Url.Action("Index","Error")';
}
});
},
close: function (event, ui) {
$("#editFaxFrame").attr("src", '');
}
});
每次打开iframe时都会发生回发吗?是的,它会发生,甚至内容会呈现一段时间,并且它会变得清晰吗?没有,我没有收到任何错误。如果不进行测试,我无法完全看到问题,但显然问题是因为iframe已经创建,我会查看“if(frameSet.contentDocument)”并确保第二次满足其中一个条件。