순서
type: "GET",
url: "/i-am-catholic/catholics",
data: {
"size": 15
}
로 먼저 뿌려주는? 것이 첫번째다.
그 다음 순서가
$.ajax({
type: "GET",
url: "/i-am-catholic/catholics",
data: {
"query": ""
},
success: function (result) {
console.log(result);
let listTag = "";
if( result.content.length != 0 ){
result.content.forEach(function (item) {
listTag +=
"<li>" +
"<a href='./church_detail.html'>" +
"<div class='img-wrap'>" +
"<img src='../images/celebImg01.jpg' alt=''>" +
"</div>" +
"<p class='name'>김연아 스텔라 신부</p>" +
"<p class='church'>주교좌 명동대성당</p>" +
"</a>" +
"</li>"
});
$(".fatherList-wrap").html(listTag);
}
}
});
로,
if( result.content.length != 0 ){
result.content.forEach(function (item) 는 곧
result.content 안에 있는 애들을 반복한다는 뜻이다.
콘솔 찍고, 나오는거 보고(1), 한개 이상일땐 뿌려줘야 하니까 if문 쓰고,
반복문(foreach)쓰고, 어떤 걸 돌려줘야 하는지 본다.
"query": "" 는 검색어, 빈 값이어도 넘겨주는 것
$(function(){
getFather();
});
let page=1;
function getFather() {
let query=$(".query").val();
$.ajax({
type: "GET",
url: "/i-am-catholic/priests",
data: {
"query": query
},
success: function (result) {
console.log(result);
let listTag = "";
if( result.content.length != 0 ){
result.content.forEach(function (item) {
listTag +=
"<li>" +
"<a href='./church_detail.html'>" +
"<div class='img-wrap'>" +
"<img src='../images/celebImg01.jpg' alt=''>" +
"</div>" +
"<p class='name'>"+item.name+"</p>" +
"<p class='church'>"+item.church+"</p>" +
"</a>" +
"</li>"
});
$(".fatherList-wrap").html(listTag);
}else{
$(".fatherList-wrap").html(listTag);
}
}
});
}
<div class="search-box mt30">
<input type="text" class="church-input mr10 query" onkeyup="getFather();" placeholder="신부님 또는 성당명을 검색해주세요.">
<a onclick="getFather();" class="search-btn">검색</a>
</div>
$(function(){
getFather();
});
let page=1; //페이지 변수선언
function getFather() {
let query=$(".query").val(); //input text 검색어
$.ajax({
type: "GET",
url: "/i-am-catholic/priests",
data: {
"query": query, //검색어 api 넘기는 값
"page": page-1 //페이지 api 넘기는 값
},
success: function (result) {
console.log(result);
let listTag = "";
if( result.content.length != 0 ){ //결과값이 0이 아닐 경우
result.content.forEach(function (item) {
listTag +=
"<li>" +
"<a>" +
"<div class='img-wrap'>" +
"<img src='../images/celebImg01.jpg' alt=''>" +
"</div>" +
"<p class='name'>"+item.name+"</p>" +
"<p class='church'>"+item.church+"</p>" +
"</a>" +
"</li>"
});
$(".fatherList-wrap").html(listTag);
}else{
$(".fatherList-wrap").html(listTag);
}
fPagination(result, page); //페이지네이션 생성 함수 호출
}
});
}
$("#pagination").on("click", "a", function() { //a태그(자세히보기 상위 태그) 클릭 시
page = parseInt($(this).attr("gopage")); //페이지이동, a태그의 seq를 가지고
getFather();
});