django-endless-pagination似乎没有使用AJAX [英] django-endless-pagination doesn't seem to be using AJAX
问题描述
这是我的查看代码:
@page_template('ajax_test_page.htm')
def ajax_test(request,template ='ajax_test.htm',extra_context = None):
context = {'dreams':Dream.objects.all()}
如果extra_context不为None:
context.update(extra_context)
返回render_to_response(template,context,context_instance = RequestContext(request))
这是ajax_test.html:
<!DOCTYPE html>
{%block js%}
< script src =http://code.jquery.com/jquery-latest.js>< / script>
< script src ={{STATIC_URL}} endless_pagination / js / endless-pagination.js>< / script>
< script> $。endlessPaginate({
paginateOnScroll:true,
paginateOnScrollMargin:20
});
< / script>
{%endblock%}
< h2> Ajax Test< / h2>
{%include page_template%}
这是ajax_test_page.htm:
{%load endless%}
{%paginate dreams%}
< div>
{梦想中的梦想%}
梦想标题:{{dream.title}}< br>
{%endfor%}
< / div>
{%show_more%}
我得到的结果与使用Django的内置在分页。我看到十个条目和一个更多链接的列表;当我点击更多链接时,我被带到/ ajax_test /?page = 2,这涉及刷新整个页面(而不是附加一组新的条目),而不是我想要做的。滚动到底部也没有效果,尽管设置了这样做的标志。
我甚至在浏览器中完全禁用了JavaScript,并没有改变任何内容,这表示javascript由于某种原因而被完全忽略。相同的结果在Chrome和Firefox。
我做错了什么?
我遇到同样的问题。您必须将呼叫转到 endlessPaginate
与
$(document).ready(function(){
$ .endlessPaginate({
paginateOnScroll:true,
paginateOnScrollMargin:20
});
} );
我们将修复文档asap
I'm attempting to use django-endless-pagination in my project, but the results don't appear to be using AJAX. My goal is twitter-like pagination, where you scroll down and more elements are listed without refreshing the page.
This is my view code:
@page_template('ajax_test_page.htm')
def ajax_test(request, template='ajax_test.htm', extra_context=None):
context = { 'dreams': Dream.objects.all() }
if extra_context is not None:
context.update(extra_context)
return render_to_response(template, context, context_instance=RequestContext(request))
This is ajax_test.html:
<!DOCTYPE html>
{% block js %}
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="{{ STATIC_URL }}endless_pagination/js/endless-pagination.js"></script>
<script>$.endlessPaginate({
paginateOnScroll: true,
paginateOnScrollMargin: 20
});
</script>
{% endblock %}
<h2>Ajax Test</h2>
{% include page_template %}
And this is ajax_test_page.htm:
{% load endless %}
{% paginate dreams %}
<div>
{% for dream in dreams %}
Dream title: {{ dream.title }}<br>
{% endfor %}
</div>
{% show_more %}
The result I get is no different than using Django's built-in paginator. I see a list of ten entries and a "more" link; when I click the "more" link, I'm taken to "/ajax_test/?page=2", which involves refreshing the entire page (rather than appending a new set of entries) and is not what I want to do. Scrolling to the bottom also has no effect despite having set the flags to do so.
I've even completely disabled javascript in the browser and it didn't change anything, signifying that the javascript is just going completely ignored for some reason. Same results in Chrome and Firefox.
What am I doing wrong?
I ran into the same problem. You have to wrap the call to endlessPaginate
with
$(document).ready(function() {
$.endlessPaginate({
paginateOnScroll: true,
paginateOnScrollMargin: 20
});
});
We'll fix the documentation asap
这篇关于django-endless-pagination似乎没有使用AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!