我想要加载一个模板,一旦我的索引页面加载。我的索引页面包含:
<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>发布于 2012-02-22 18:13:22
问题是远程模板是由ICanHaz异步获取的,当我想使用它们呈现页面时,它们是不可用的。
我找到了两种不同的解决方案:
1)使用脚本标签直接在页面中定义模板。这对我来说有点难看。
2)同步ICanHaz调用。如果你只有很少的模板,这是一个合理的权衡。我将这段代码从:
$.ajax({url: script.prop('src'), dataType: 'text',至
$.ajax({async: false, url: script.prop('src'), dataType: 'text',这就是问题所在。
发布于 2013-05-08 16:50:11
执行ich.refresh()以加载使用ajax加载的模板
https://stackoverflow.com/questions/9380031
复制相似问题