-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"><<</a></li>
{% if properties.has_previous %}
<li><a href="?{{ path }}&page={{ properties.previous_page_number }}">Anterior</a></li>
{% else %}
<li><a href="#">Anterior</a></li>
{% endif %}
{% if properties.has_next %}
<li><a href="?{{ path }}&page={{ properties.next_page_number }}">Siguiente</a></li>
{% else %}
<li><a href="#">Siguiente</a></li>
{% endif %}
<li><a href="?{{ path }}&page={{ properties.paginator.num_pages }}">>></a></li>
</ul>
</div>
콘솔에 오류가 있습니까? –