【发布时间】:2011-05-10 23:24:28
【问题描述】:
我知道我在某个地方弄乱了语法,但我不知道在哪里。代码如下。 (我省略了body标签,因为它在预览中没有正确显示)
<head runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery.tmpl.js" type="text/javascript"></script>
<script src="Scripts/jquery.tmplPlus.js" type="text/javascript"></script>
<script id="ProductsTemplate" type="text/x-jquery-tmpl">
<table class="productsHere">
<thead>
<tr>
<td>Title</td>
<td>Size</td>
<td>Price</td>
</tr>
</thead>
<tbody>
{{each data}}
{{tmpl($value) '#ProductsRowTemplate'}}
{{/each}}
</tbody>
</table>
</script>
<script id="ProductsRowTemplate" type="text/html">
<tr>
<td class="title">${title}</td>
<td class="size">${size}</td>
<td class="price">${price}</td>
</tr>
</script>
<title>Using JQuery</title>
</head>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "JSON-WebService.asmx/getProducts",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('#ProductsTemplate').tmpl(data).appendTo('#ProductsTable');
alert("It works");
},
failure: function (data) {
alert("It didn't work");
}
});
});
</script>
<div id="ProductsTable"></div>
<div id="OthersTable"></div>
<div></div>
</form>
【问题讨论】:
-
您收到的错误信息是什么?
-
根据我的警报,我可以得到:“它可以工作”,但表格没有呈现。我看到的只是标题。我也没有收到错误消息。
标签: jquery html html-table jquery-templates