A
A
aumarov1112014-06-26 17:11:37
JavaScript
aumarov111, 2014-06-26 17:11:37

How to add html using templating engine?

I am using the underscore template engine.

$(document).on("click", ".load-more a", function(){
    var id = $('.products').children('li:last').data('id');
    inputs = $(".filter form").serializeArray();
    var template = $("#products").html();

    $.ajax({
      type: "post",
      url: "/loadmore",
      data: { "id":id, "inputs":inputs },
      beforeSend: function() {
            $(".loader").css('display', 'block');
        },
      success: function(result) {
              setTimeout(function(){
                $(".loader").css('display', 'none');
              }, 500);
              $(".products").append(_.template(template,{ result:result, manufacturers:manufacturers, country:country }));
          },
    });
  });

you do not need to redraw the view, you need to add blocks to the existing ones, since this button is responsible for reloading products. Can this be done with Underscore? And if not, how about using regular jquery?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zhak, 2014-06-26
@romanzhak

Use this micro-templater and the jQuery append function to load content:
ejohn.org/blog/javascript-micro-templating

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question