2014-06-13 117 views
4

虽然我在主视图的iframe中渲染ajax的部分视图。和它的作品在当地正常,但发布其作品后,只有第一次第二次它清除iframe的身体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", ''); 
     } 

    }); 
+0

是否每当您的iframe打开回发发生? –

+0

其发生的内容即使是内容呈现的时候,它的变得清晰 – Kajal

+0

你有没有什么错误? –

回答

2

我解决了这个问题之后,那么多[R &双放的setTimeout()函数对阿贾克斯成功

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

    });