【问题标题】:Iframe not rendering contents second timeiframe 不第二次呈现内容
【发布时间】:2014-08-03 15:02:45
【问题描述】:

我在主视图的 Iframe 中通过 ajax 渲染部分视图。它在本地运行良好,但仅在第一次发布其作品后第二次清除 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", '');
        }

    });

【问题讨论】:

  • 每次打开 iframe 时都会发生回发吗?
  • 是的,即使内容渲染一段时间,它也会变得清晰
  • 你有什么错误吗?
  • 不,我没有收到任何错误
  • 如果没有测试,我无法直接看到问题,但显然问题是因为 iframe 已经创建,我会查看代码的“if (frameSet.contentDocument)”部分并确保一个第二次满足这些条件。

标签: javascript jquery ajax iframe asp.net-mvc-5


【解决方案1】:

经过这么多的研发,我解决了这个问题,我把 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", '');
        }

    });

【讨论】:

    猜你喜欢
    • 2016-09-14
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 2020-01-31
    • 2019-07-30
    • 2017-03-16
    • 1970-01-01
    • 2012-04-21
    相关资源
    最近更新 更多