본문 바로가기
Developer/Javascript & jQuery

[jQuery] ajax로 결과를 찾아서 jQuery id로 찾아서 배치하기

by 순수한소년 2022. 2. 28.
728x90
반응형

ajax dataType을 html로 리턴받을 때, 리턴페이지의 부분만 찾아서 호출한 현재페이지에 배치하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    /* 데이터 조회 */
    function getContentsData() {
        $('#pageIndex').val('1');
        $('html').scrollTop(0);
        var searchDescStatus = $('.unify .searchDesc').css('visibility');
        $('.searchDesc').hide();
 
        $.ajax({
            method: 'post',
            url: '/sch/ajaxSearchList-data.do',
            data: $("#listForm, #schPopLayerForm").serialize(),
            dataType: 'html',
            cache: false
        })
        .done(function(responseHtml) {
            $('.txtResult').html($(responseHtml).find('#txtResultAjax').html());    //검색결과
            $('.dashboard').html($(responseHtml).find('#dashboardAjax').html());    //dashboardAjax
 
            var currentSearchPastCd = $("#selectBox_searchPastCd").val();    //생산기관
            if(""!=currentSearchPastPrsdCd){
                $('.agency').html($(responseHtml).find('#agency').html());
            } else {
                fn_reset_selectBox_searchIntt();
            }
 
            highlight();    //getContentsData
            $.end_loding();
        });
    }
cs

@

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="snft.cmm.Constant" %>
 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="cfn" uri="/WEB-INF/tlds/func.tld" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
 
<% pageContext.setAttribute("newLineChar", "\n"); %>
 
<p class="txtResult" id="txtResultAjax">
    상세검색 결과 <span class="tit02"><fmt:formatNumber value="${totalCnt }" pattern="#,###" /></span>건입니다.
</p>
 
<div class="dashboard" id="dashboardAjax">
    <div class="sequence">
        <button type="button" id="btnSearchOrderby" data-orderBy="<c:out value="${paramVO.searchOrderby}" />">
            <c:choose><c:when test="${paramVO.searchOrderby eq 'date_desc'}">최신순</c:when><c:otherwise>오래된순</c:otherwise></c:choose>
            <span><img src="/images/icon/icon-topbot-arr.png" alt="화살표"></span>
        </button>
    </div>
    <!-- resultList ########################################################################################################## -->
    <c:forEach items="${resultList}" var="result" varStatus="status">
    
    </c:forEach>
    <!-- // resultList E ##################################################################################################### -->
 
    <c:if test="${empty resultList or fn:length(resultList) == 0}">
        <div class="noData" style="color:#ffffff; padding: 100px; text-align:center;">
            검색된 데이터가 존재하지 않습니다.
        </div>
    </c:if>
</div>
 
<dl id="agency">
    <dt class="tit03">생산기관</dt>
    <dd>
        <select class="leftCol_selectBox" id="selectBox_searchIntt" name="selectBox_searchIntt" title="생산기관" >
            <option value="">생산기관 전체</option>
            <c:forEach items="${comCodeInttList}" var="comCodeInttList" varStatus="status">
                <option value="${comCodeInttList.cdId}" <c:if test="${comCodeInttList.cdId == paramVO.searchIntt}"> selected</c:if> >${comCodeInttList.cdNm}</option>
            </c:forEach>
        </select>
    </dd>
</dl>
 
 
 
cs

@

 

 

반응형