I am trying to dynamically load new content when the user reaches the end of the page. My web application uses gae-python. I use ajax and jquery to update the request in html.
HTML
{% block content %} <div class="hero-unit special-padding"> {% for h in hots %} {{ h.imageid.get().render() | safe }} {% endfor %} {% include 'pager.html' %} </div> {% endblock %}
JQuery and AJAX:
$(window).scroll(function () { if ($(window).scrollTop() + $(window).height() > $('.hero-unit').height() - 100 && !isLoading) {$('#loadpage').click(function() { var page=$('#loadpage').attr('name'); $.ajax({ type: "POST", dataType:"json", url: '/loadpage', data : {'page': page}, success: updatehtml, }); return false; }); }); function updatehtml(e){ for (var i = 0; i < e.length; i++) { var html= "{{ "+e[i]['imageid']+".get().render() | safe }}"; $('.hero-unit').append(html); } }
I serialize the data warehouse object and pass it as json. It will update the HTML using
{{ datastoreKey.get().render()|safe }}
Now I want the jinja2 framework to call the python .render() function whenever ajax updates my HTML.
I know this can be done differently by writing all the HTML in javascript, but I want to know if there is another simple / better way to do this.
source share