我的主HTML文件在內容中動態加載;JQuery AJAX load()&ready()
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
</head>
<body>
Loading please wait
<script type="text/javascript">
$(document).ready(function(){
$('body').load("remotePage.html");
});
</script>
</body>
</html>
remotePage.html是;
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script2.js"></script>
<script type="text/javascript" src="script3.js"></script>
</head>
<body>
<script type="text/javascript">
function init(){
someFunctionThatDependsOnAllScripts(); //Fails because all scripts is not yet loaded
}
$(document).ready(init);
<script>
</body>
</html>
它失敗了,因爲在加載script1.js之前調用了script1.js中的ready。 加載回調似乎沒有幫助。
$(function(){
$('body').load("remotePage.html", function(){
init(); //doesn't work either
});
});
如何判斷remotePage.html所需資源加載完成的所有ajax操作何時結束? 如何解決?
感謝
你必須首先包括jQuery庫... – 2012-03-18 15:05:44