我在主视图的 Iframe 中通过 ajax 呈现部分 View 。它在本地运行良好,但在第一次发布其作品后第二次清除 iframe 主体
这是我的代码:
$('#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", '');
}
});
关于javascript - iframe 第二次不呈现内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24198776/