django.core.paginator使用jQuery进行Ajax分页

django.core.paginator使用jQuery进行Ajax分页,第1张

django.core.paginator使用jQuery进行Ajax分页

我没有发现错误,但下面向您展示如何解决此任务。我认为您可以轻松地使其适应您的需求

jQuery ajax部分:

<script type="text/javascript">function ajax_get_update()    {       $.get(url, function(results){          //get the parts of the result you want to update. Just select the needed parts of the response          var table = $("table", results);          var span = $("span.step-links", results);          //update the ajax_table_result with the return value          $('#ajax_table_result').html(table);          $('.step-links').html(span);        }, "html");    }//bind the corresponding links in your document to the ajax get function$( document ).ready( function() {    $( '.step-links #prev' ).click( function(e) {        e.preventDefault();        url = ($( '.step-links #prev' )[0].href);        ajax_get_update();    });    $( '.step-links #next' ).click( function(e) {        e.preventDefault();        url = ($( '.step-links #next' )[0].href);        ajax_get_update();    });});//since the links are reloaded we have to bind the links again//to the actions$( document ).ajaxStop( function() {    $( '.step-links #prev' ).click( function(e) {        e.preventDefault();        url = ($( '.step-links #prev' )[0].href);        ajax_get_update();    });    $( '.step-links #next' ).click( function(e) {        e.preventDefault();        url = ($( '.step-links #next' )[0].href);        ajax_get_update();    });});</script>

模板html部分:

<div > <span >     {% if object_list.has_previous %}     <a id="prev" href="?{{ urlquerystring_previous_page }}">previous</a>     {% else %}     <span >previous</span>     {% endif %}     <span >     Page {{ object_list.number }} of {{ object_list.paginator.num_pages }}.     </span>     {% if object_list.has_next %}      <a id="next" href="?{{ urlquerystring_next_page }}">next</a>     {% else %}      <span >next</span>     {% endif %} </span>        </div> <form  id="action-selecter" action="{{ request.path }}" method="POST"> <div id="ajax_table_result">     <table  cellspacing="5">         <thead>  {% table_header headers %}         </thead>  <tbody>    ....


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5174359.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-18
下一篇2022-11-18

发表评论

登录后才能评论

评论列表(0条)

    保存