简体   繁体   English

iframe第二次不渲染内容

[英]Iframe not rendering contents second time

I am rendering partial view though ajax in Iframe of Main View. 我通过主视图的iframe中的ajax渲染局部视图。 And it works fine locally but after publish its works only first time second time it clears iframe body 并且它在本地工作正常,但在第二次发布它的作品后它第一次清除iframe体

Here is My Code: 这是我的代码:

  $('#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", '');
        }

    });

I solved This Issue after so much r&d i put Settimeout() function on ajax success 经过这么多研究后我解决了这个问题,我把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", '');
        }

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM