2014-04-04 3 views
0

타사 컨트롤을 사용하여 Pdf를로드하는 중입니다. 여기서 Pdf는 지연로드됩니다. 내 시나리오에서는 내가 페이지로드에서 몇 페이지를로드 할과 PDF 파일의 내가 원하는,하지만 난에 남아있는 페이지를로드 할 사전로드 수행 이제 코드 위의 pages to load at background.Jquery를 사용하여 백그라운드에서 메서드를 실행하는 방법?

// Load the required pages at the Load. 
function PreLoadPdf(startpage, endpage) { 
    myApi.addEventListener("rendered", function() { 
     for (var i = startpage; i <= endpage ; i++) { 
      myApi.getPage(i).loadRendered(); 
     } 
    }); 
} 

의 나머지를로드 할 배경. How to execute the Jquery Method at the background of the page without freezing the page. 또한 내가 사용 안하고,

setTimeout(function() {}

+0

사용 아약스 .. –

+0

방법, actully 사용자는 페이지의 나머지는 배경에서로드해야합니다 동안 그는 단지 독자의 일부 페이지를 보려면 로딩 대해 의심하지 않습니다 –

답변

1

이 문제를 해결하는 방법은 여러 가지가 있습니다,하지만 가장 좋은 방법은 jQuery의 promise API를 사용하는 것입니다 생각합니다. 그것에 대해

//Untested code... typed on the fly 
//May have minor syntax errors. 

var fileList = [ 
    "http://example.com/file1.pdf", 
    "http://example.com/file2.pdf" 
]; 


var promiseArray = []; 

// Fill the file promise array 
for (var i = 0; i < fileList.length; i++) { 
    var promise = $.get(fileList[i]); 
    promiseArray.push(promise); 
    }); 
} 

$.when.apply($, promiseArray).then(function() {  
    // All have been resolved (or rejected), do your thing  
}); 
관련 문제