In this code, j correctly becomes an object: j.name, j.addr, j.city, j.state, and j.zip. However the success function has a JavaScript error of .tmpl()
isn't a function.
<script id="addressTemplate" type="text/x-jquery-tmpl">
{{tmpl "addressTemplate"}}
<tr><td>Name: ${name}</td></tr>
<tr><td>Address: ${addr}</td></tr>
<tr><td>City: ${city}</td></tr>
<tr><td>State: ${state}</td></tr>
<tr><td>Zip: ${zip}</td></tr>
</script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "Home/GetInfo",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (j) {
$("#addressTemplate").tmpl(j).appendTo("#result");
}
});
});
</script>
<div id="result"></div>
What am I doing wrong to call JQuery 1.5 templates?
jQuery templates didn't make it in the core jQuery script. You still need to include jquery.tmpl.js. Here is John Resig's comment.