2015-04-20 11 views
0

您好我有一個JQuery函數調用控制器時,控制器響應(成功())它正在加載一個iFrame; 基本上;轉換器30秒後成功返回的功能,對於這個原因,我想顯示使用JavaScript顯示加載程序,而控制器響應

beforeSend: function() 
{ 
}, 

功能我嘗試了很多,但它不工作加載圖像;你能否給我建議,我該如何實現它。我的代碼給出波紋管:

var callController = function (FirstName, documentId, fileName, packet) { 
    $.ajax({ 
     type: "POST", 
     url: "http://localhost:63902/Home/Preview?DocumentId=" + documentId + "&FileName=" + fileName + "&packet=" + packet, 
     cache: false, 
     async: false, 

     //controller happens... 

     success: function (returnedValue) { 
      rememberDocumentId(documentId); 
      location.reload("#mainIframe"); 
      setTimeout(function() { 

      }, 3000); 

      document.getElementById("mainIframe").style.display = "none"; 
      document.getElementById("documentIframe").style.display = "block"; 
      document.getElementById("documentIframe").src = "http://localhost:63902/FileProcessing/PDFProcessing/TempPDF/" + returnedValue; 

      event.preventDefault(); 
     }, 
     error: function (jqXHR, textStatus, errorThrown) { 
      alert(jqXHR + " " + textStatus + " " + errorThrown); 
     } 
    }); 

}; 
+1

VAR呼叫管理功能=(名字,documentId,文件名,SL){//可以顯示裝載機這裏 –

+0

嗨 我想打電話給Loader.html
的document.getElementById (「mainIframe」)。src =「http:// localhost:63902/Loading.html但不起作用 –

+0

你可以在這裏做什麼問題? –

回答

1

可以後或$.ajax({...})之前顯示您的裝載機的權利,但你應該從不使用async:false,這是根邪惡的,它會凍結瀏覽器,而要求有沒有成功。

這樣的:

var callController = function (FirstName, documentId, fileName, SL) { 
//here 
showLoader(); 
$.ajax({ 
    type: "POST", 
    url: "http://localhost:63902/Home/Preview?DocumentId=" + documentId + "&FileName=" + fileName + "&SL=" + SL, 
    cache: false, 

    //controller happens... 

    success: function (returnedValue) { 
     rememberDocumentId(documentId); 
     location.reload("#mainIframe"); 
     setTimeout(function() { 

     }, 3000); 

     document.getElementById("mainIframe").style.display = "none"; 
     document.getElementById("documentIframe").style.display = "block"; 
     document.getElementById("documentIframe").src = "http://localhost:63902/FileProcessing/PDFProcessing/TempPDF/" + returnedValue; 
     //hide Here 
     hideLoader(); 
    }, 
    error: function (jqXHR, textStatus, errorThrown) { 
     alert(jqXHR + " " + textStatus + " " + errorThrown); 
     //hide Here 
     hideLoader(); 
    } 
}); 
} 
+0

我想朱尼厄斯Rendel的解決方案,但有下列錯誤:在第62行 未處理的異常,在HTTP列12135://本地主機: 49664/fa4753a5553f47a5964e056d13af0c39/browserLink 0x8000ffff - JavaScript運行時錯誤:無效的調用對象 如果存在此異常的處理程序,則可以安全地繼續該程序。 而我的showLoader()如下所示: var ShowLoader = function(){ location.reload(「#documentIframe」); // alert(「我在Loader中」); document.getElementById(「documentIframe」)。src =「http:// localhost:63902/Loading.html」; } –

+0

請問可以告訴錯誤在哪裏? – n00dl3

+0

順便說一句,你爲什麼使用iframe?他們是如此痛苦... – n00dl3

相關問題