Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery 1.5 templates: JQuery 1.5 didn't render my template. How do you call JQuery 1.5 templates?

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?

like image 223
Zachary Scott Avatar asked Dec 10 '25 04:12

Zachary Scott


1 Answers

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.

like image 116
Atanas Korchev Avatar answered Dec 13 '25 11:12

Atanas Korchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!