공부하자/웹개발일지

[웹개발일지] #5. 실시간 달러 환율 달기

snbrin 2022. 3. 6. 15:55

 

 

첫번째 과제물에 환율 정보 뿌리기!!😁

 

💻두번째 과제물💻

👉로딩이 완료되면, 환률 API를 이용해 실시간 환율 표시하기

 


 

💻완성💻

 

여기서 상기해야할 것은?

👉 ajax의 기본 형식

👉 로딩 완료 후 바로 환율을 표시하기

== 로딩 후 바로 호출

$(document).ready(function(){ alert('다 로딩됐다!') });

$(document).ready(function () { get_rate(); });

<head>
	<style>
        .dol{
            color: blue;
        }
    </style>

    <script>
        $(document).ready(function () {
            fnrate();
        });

        function fnrate(){
             $.ajax({
                type: "GET",
                url: "http://spartacodingclub.shop/sparta_api/rate",
                data: {},
                success: function (response) {
                    let now_rate = response['rate'];
                    $('#realrate').text(now_rate);
                }
            })
        }

    </script>
</head>

<body>
<div class="wrap">
    <div class="dinos">
        <p class="dol">달러-원 환율 : <span id="realrate">0000.00</span></p>
    </div>
</div>
</body>

</html>

첫번째 과제물에 위 코드를 알맞은 태그 안에 삽입하기만 하면 끝.