본문 바로가기
웹 개발 공부중

ajax 온도 가져오기

by redeyes 2021. 12. 14.

$(document).ready(function (){}  = 문서가 준비되면 실행하라는 의미로 이해했는데 , 습관적으로 꼭 넣어주면 좋을거 같다 .  

<script>
        $(document).ready(function (){
            $.ajax({
            type : "GET",
            url : "http://spartacodingclub.shop/sparta_api/weather/seoul",
            data : "",
            success(response){
                console.log(response['temp']);
                let temp = response['temp'];
                $('#temp').text(temp);
            }
        })
        });

    </script>

그러나 다른 자료나 다른 고수님들을 보면 이거 사용을 피하라는데 정확히 이해는 가지 않는다.

 

 <!doctype html>
<html lang="ko">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <title>서울 온도 가져오기</title>    
    <script>
        $(document).ready(function (){
            $.ajax({
            type : "GET",
            url : "http://spartacodingclub.shop/sparta_api/weather/seoul",
            data : "",
            success(response){
                console.log(response['temp']);
                let temp = response['temp'];
                $('#temp').text(temp);
            }
        })
        });

    </script>
</head>

<body>
 <p>현재기온 : <span id="temp">00.0</span></p>
</body>
</html>

'웹 개발 공부중' 카테고리의 다른 글

파이썬 크롤링 기초  (0) 2021.12.15
python requests 활용  (0) 2021.12.14
ajax 따릉이 데이터가져오기  (0) 2021.12.14
ajax , json , jquery 다루기  (0) 2021.12.14
jQuery 이용해서 div박스 열고 닫기  (0) 2021.12.14