ajax 숙제

Jo_oJ·2022년 3월 8일
0

스파르타코딩클럽

목록 보기
8/12

원리를 모르니까 계속 헛도는 느낌...

핑 찍는거 계속 헷갈린다
이번 숙제는 달러-원 환율:(금액) 에서 금액값 불러오는거 했음

  • jabascript 페이지 로드 후 실행하기
        $(document).ready(function() {
            // func();
        });

정답

	<style>
        .rate_color {
            color:blue;
        }
    </style>
    <script>
        $(document).ready(function() {
            get_rate()
        });

        function get_rate() {
            $.ajax({
                type: "GET",
                url: "https://api.manana.kr/exchange/rate.json",
                data: {},
                success: function (response) {
                    let now_rate = response[1]['rate']
                    $('#now_rate').text(now_rate)

                }
            })
        }

    </script>
    <body>
           <p class="rate_color">달러-원 환율:<sapn id="now_rate">9999</sapn></p>
    </body>

내가한거

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

        function q1() {
            $.ajax({
                type: "GET",
                url: "https://api.manana.kr/exchange/rate.json",
                data: {},
                success: function (response) {
                    let rate = response[1]['rate']

                    let temp_html = `<p id="q1">달러·원 환율:rate</p>`
                    $('#q1').append(temp_html)

                }
            })
        }

    </script>

<body>
        <p id="q1"></p>
</body>

0개의 댓글

관련 채용 정보