최정민

FEAT : ajax버튼을 이용한 api

-
...@@ -277,8 +277,8 @@ router.get("/recommend", function (req, res) { ...@@ -277,8 +277,8 @@ router.get("/recommend", function (req, res) {
277 if (err) { 277 if (err) {
278 console.log(err); 278 console.log(err);
279 } else if (row.length > 0) { 279 } else if (row.length > 0) {
280 - console.log(row); 280 + console.log(row[0].CAFE_ID);
281 - res.send(row); 281 + res.send({result:row});
282 } 282 }
283 }); 283 });
284 } 284 }
......
1 +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1622591147463,"user":{"email":"cjm2021401@khu.ac.kr","picture":"https://lh3.googleusercontent.com/a/AATXAJzFD3R6CaL2NpysVrfvdGqcQ83vh_wpbN_5hj-0=s96-c","nickname":"초보베이시스트","age":16,"gender":"male"}}
...\ No newline at end of file ...\ No newline at end of file
...@@ -158,6 +158,8 @@ ...@@ -158,6 +158,8 @@
158 158
159 <div class="col-1"></div> 159 <div class="col-1"></div>
160 </div> 160 </div>
161 + <button type="button" id='Recommend' class="btn btn-primary" onclick="recommend();">추천</button>
162 + <p id='test'></p>
161 </section> 163 </section>
162 164
163 <script 165 <script
...@@ -165,6 +167,22 @@ ...@@ -165,6 +167,22 @@
165 src="//dapi.kakao.com/v2/maps/sdk.js?appkey=68cbccbcd6f0fef0a213e62ad37393ee&libraries=services" 167 src="//dapi.kakao.com/v2/maps/sdk.js?appkey=68cbccbcd6f0fef0a213e62ad37393ee&libraries=services"
166 ></script> 168 ></script>
167 <script> 169 <script>
170 + function recommend(){
171 +
172 + $.ajax({
173 + url: '/recommend',
174 + type: 'GET',
175 + success:function (result){
176 + if (result) {
177 + $('#test').html(result.result[0].CAFE_ID);
178 + }
179 + }
180 + });
181 +
182 + }
183 + </script>
184 +
185 + <script>
168 var lat = ""; 186 var lat = "";
169 var lon = ""; 187 var lon = "";
170 var placeOverlay = new kakao.maps.CustomOverlay({ zIndex: 1 }); 188 var placeOverlay = new kakao.maps.CustomOverlay({ zIndex: 1 });
......