본문 바로가기
💻 개발블로그/웹개발

Ajax 팬명록에 온도 적용하기

by August.J 2021. 12. 14.

Ajax는 굳이 암기하지 않아도 끌어와서 사용해도 된다!

 

아래 코드에서 기온을 적용할때 <p>태그사용, <span>으로 일정부분 담아준 뒤에 아이디를 붙였다.

 

-이미지url을 적용시킬때는:

$('#아이디').attr("src",이미지url)

 

-텍스트를 적용시킬때는

S('#아이디').txt("텍스트")

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

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>

<title>스파르타코딩클럽 | BTS팬명록</title>

    <link href="https://fonts.googleapis.com/css2?family=Gamja+Flower&family=Jua&display=swap" rel="stylesheet">

    <style>
        * {
            font-family: 'Gamja Flower', cursive;
            font-family: 'Jua', sans-serif;
        }

        .mytitle {

            width: 100%;
            height: 250px;

            background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("https://img.buzzfeed.com/buzzfeed-static/static/2021-05/21/15/asset/e6dd9f2189d1/sub-buzz-1688-1621612188-25.png?downsize=1600:*&output-format=auto&output-quality=auto");
            background-position: center;
            background-size: cover;

            color: white;

            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        .mypost {
            max-width: 400px;
            width: 95%;

            margin: 20px auto 20px auto;

            box-shadow: 0px 0px 3px 0px gray;
            padding: 20px;
        }

        .card{
            max-width: 400px;
            width: 95%;

            margin: 0px auto 10px auto;
            padding: 10px 15px 10px 15px;
        }

        .mypost > button {
            width:130px;

            margin-top: 10px;

            border-radius: 5px;
        }
    </style>

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

        });
    </script>

</head>

<body>
        <div class="mytitle">
            <h1>BTS 팬명록</h1>
            <p>현재기온 : <span id="temp">00.00도</span></p>
        </div>

        <div class="mypost">

            <div class="form-floating mb-3">
                <input type="text" class="form-control" id="name" placeholder="url">
                <label for="floatingInput">닉네임</label>
            </div>
            <div class="form-floating">
            <textarea class="form-control" placeholder="Leave a comment here" id="comment"
                      style="height: 100px"></textarea>
                <label for="floatingTextarea2">응원댓글</label>
            </div>
            <button onclick type="button" class="'btn btn-dark">응원남기기</button>


        </div>

        <div class="cards">
             <div class="card">
                <blockquote class="blockquote mb-0">
                    <p>새로운 앨범 너무 멋져요 !</p>
                    <footer class="blockquote-footer">아미1
                    </footer>
                </blockquote>
            </div>
            <div class="card">
                <blockquote class="blockquote mb-0">
                    <p>새로운 앨범 너무 멋져요 !</p>
                    <footer class="blockquote-footer">아미2
                    </footer>
                </blockquote>
            </div>
            <div class="card">
                <blockquote class="blockquote mb-0">
                    <p>새로운 앨범 너무 멋져요 !</p>
                    <footer class="blockquote-footer">아미3
                    </footer>
                </blockquote>
            </div>
        </div>

</body>

</html>