2014-08-30 6 views
-1

Im 내 앱에 간단한 검색 엔진을 구축하여 특정 기준에 따라 일부 재개를 만들었습니다. 아약스와 jquery를 사용하여 아약스를 사용하여 검색을 구현하고 결과에 페이지 매김을하고 싶습니다. Ajax는 검색 작업을 잘 처리하지만 결과에 페이지 매기기를 시도 할 때 처음 또는 다음에 두 번째로 작동하고 두 번째로 중단 될 때만 작동합니다.Django와 Jquery로 Ajax 페이지 매김

(function(){ 

$("form#search").on("submit", function(event){ 

    event.preventDefault(); 
    var $this = $(this); 


    $.ajax({ 

     type:"GET", 
     dataType:"html", 
     data:$this.serialize(), 
     url:"/properties/search/", 
     success:function(resp){ 

      $(".col-md-9").html($(resp).find(".properties")); 

     }, 
     error: function(){ 

      $(".col-md-9").html('<h1>Verifique los datos ingresados para realizar una correcta búsqueda</h1>'); 

     } 

    }) 

}) 

})(); 

// 매김

(function(){ 

$("ul.pagination li a").on("click", function(event){ 

    $this = $(this); 
    console.log($this.prop("href")); 
    event.preventDefault(); 

    $.ajax({ 

     type:"GET", 
     dataType:"html", 
     url:$this.prop("href"), 
     success:function(resp){ 

      $(".col-md-9").html($(resp).find(".properties")); 

     }, 
     error: function(){ 

      $(".col-md-9").html('<h1>Verifique los datos ingresados para realizar una correcta búsqueda</h1>'); 

     } 

    }) 

}) 

})(); 

// 템플릿

 <div class="text-center"> 
        <ul class="pagination"> 
         <li><a href="/properties/search">&lt;&lt;</a></li> 
         {% if properties.has_previous %} 
          <li><a href="?{{ path }}&amp;page={{ properties.previous_page_number }}">Anterior</a></li> 
         {% else %} 
          <li><a href="#">Anterior</a></li> 
         {% endif %} 
         {% if properties.has_next %} 
          <li><a href="?{{ path }}&amp;page={{ properties.next_page_number }}">Siguiente</a></li> 
         {% else %} 
          <li><a href="#">Siguiente</a></li> 
         {% endif %} 
         <li><a href="?{{ path }}&amp;page={{ properties.paginator.num_pages }}">&gt;&gt;</a></li> 
        </ul> 
       </div> 
+0

콘솔에 오류가 있습니까? –

답변

-1

내가 ("클릭"$ (문서) CSTE 연구진를 사용하여 문제를 해결, "ul.pagination의 리는" , function (event) {})

관련 문제