$(function(){ console.log('??!!???'); const currentPath = window.location.pathname; console.log(currentPath); if (currentPath !== '/web/main/mainPage.do') { if (currentPath === '/web/content.do') { fn_getSubMenu(); } } }); function fn_getSubMenu(){ var title = $('#container .sub_title').text(); var subTitle = $.trim($('.content_title').text()); console.log('title ::', title); console.log('subTitle ::', subTitle); var sendData = { "depth1MenuNm" : title , "depth2MenuNm" : subTitle } $.ajax({ type: 'POST', url: "/web/com/subMenu.do", contentType: 'application/json', data: JSON.stringify(sendData), dataType: 'json', success: function(data) { console.log(data); if(data.status == 'OK'){ renderSubVisualNav(data); } }, error: function(err) { console.error(err); } }); } // AJAX 성공 시 호출되는 함수 내부 function renderSubVisualNav(res) { const result = res.data || res; // res.data가 있으면 쓰고, 없으면 res 자체를 사용 const depth1List = result.depth1List || []; // 데이터가 없으면 빈 배열로 초기화 const depth2List = result.depth2List || []; const selected1 = result.selectedDepth1; const selected2 = result.selectedDepth2; let html = ''; // 1. 기본 홈 아이콘 html += ''; // 2. 1Depth 메뉴 생성 if (depth1List.length > 0) { // 리스트가 있을 때만 실행 html += '
'; html += ` `; html += ' '; html += '
'; } // 3. 2Depth 메뉴 생성 if (depth2List.length > 0) { html += '
'; html += ` `; html += ' '; html += '
'; } document.querySelector('.sub_visual_nav').innerHTML = html; }