2012-02-21 86 views
0

我想在加載索引頁面時加載模板。我的索引頁包含:iCanHaz.js在頁面加載時未加載模板

<script src="site/introduction.html" type="text/html"></script> 
<script src="js/lib/jquery-1.6.1.js" type="text/javascript"></script> 
<script src="js/lib/ICanHaz.js" type="text/javascript"></script> 
<script src="js/app/main2.js" type="text/javascript"></script>  

和main2.js包含:

$(function() { 
    var introduction_html = ich.introduction(); 
    $('#pm').html(introduction_html.filter('#introduction')); 
}); 

引入模板沒有找到!即使在調用它之前使用ich.grabTemplates(),它也不起作用。

我該如何解決這個問題?

introduction.html包含:

<html> 
<head> 
<style type="text/css"> 
P.submit {text-align: left} 
</style> 
</head> 

<body> 

<div id="introduction"> 

<p>The tool can now guide you, step by step, through this procedure, beginning when you click on the "start" button below.</p> 

<form action=""> 
<p class="submit"><input type="submit" value="Start" /></p> 
</form> 

</div> 

</body> 
</html> 
+0

是否有任何控制檯輸出? – 2012-02-21 15:21:46

+3

@ThomasClayson,你的意思是我** CAN HAZ CONSOLES OUTPUT?** – Jakub 2012-02-21 15:25:03

+0

我得到的錯誤 對象#有沒有方法的介紹「 – z1naOK9nu8iY5A 2012-02-21 15:26:46

回答

0

的問題是,遠程模板是通過搶異步ICanHaz,他們是不提供我想用它們來渲染頁面的時間。

我發現了兩個不同的解決方案:

1)直接與腳本代碼的網頁定義模板。這對我的口味有點醜陋。

2)使ICanHaz調用同步。如果你有幾個模板,這是一個合理的權衡。我改變了這片代碼:

 $.ajax({url: script.prop('src'), dataType: 'text', 

 $.ajax({async: false, url: script.prop('src'), dataType: 'text', 

該做的伎倆。

0

做一個ich.refresh()加載加載了AJAX的模板