Iframe does not display content a second time

I am making a partial view, although ajax in the Iframe is of the main form. And it works fine locally, but after publishing his work, only the first time, the second time clears the iframe body

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

    });
+4
source share
1 answer

I solved this problem after so many r & d I set Settimeout () function to ajax success

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

    });
+2
source

Source: https://habr.com/ru/post/1544426/


All Articles