JQuery 1.5 Templates: JQuery 1.5 did not display my template. What 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 is .tmpl()not 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 invoke jQuery 1.5 templates?

+3
source share
1 answer

jQuery templates did not do this in the core jQuery script. You still need to enable jquery.tmpl.js. Here is a comment by John Resig.

+6
source

Source: https://habr.com/ru/post/1790069/


All Articles