[マルコの学習ログ]ページ開発総合クラス第2週後期(3)


Web開発総合クラス2週間開発ログ


はじめに


jqueryとajaxの利用

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

<head>
    <meta charset="UTF-8">
    <title>jQuery 연습하고 가기!</title>

    <!-- jQuery를 import 합니다 -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <style type="text/css">
        div.question-box {
            margin: 10px 0 20px 0;
        }
        .bad {
            color: red;
        }
    </style>

    <script>
        function q1() {
            $('#names-q1').empty();
            $.ajax({
                type: "GET",
                url: "http://spartacodingclub.shop/sparta_api/seoulair",
                data: {},
                success: function (response){
                    let rows = response['RealtimeCityAir']['row'];
                    for(let i = 0; i < rows.length; i ++) {
                        let gu_name = rows[i]['MSRSTE_NM'];
                        let gu_mise = rows[i]['IDEX_MVL'];
                        let temp_html = ``
                        if (gu_mise > 110) {
                            temp_html = `<li class="bad">${gu_name} : ${gu_mise}</li>`
                        }else{
                            temp_html = `<li>${gu_name} : ${gu_mise}</li>`
                        }

                        $('#names-q1').append(temp_html);
                    }
                }
            })
        }
    </script>

</head>

<body>
    <h1>jQuery+Ajax의 조합을 연습하자!</h1>

    <hr/>

    <div class="question-box">
        <h2>1. 서울시 OpenAPI(실시간 미세먼지 상태)를 이용하기</h2>
        <p>모든 구의 미세먼지를 표기해주세요</p>
        <p>업데이트 버튼을 누를 때마다 지웠다 새로 씌여져야 합니다.</p>
        <button onclick="q1()">업데이트</button>
        <ul id="names-q1">
        </ul>
    </div>
</body>

</html>

新学のhtml

<li></li> 목록 만들기
<p></p> 문단

ajax 2の利用


現在、ソウル市大陵タクシー所の自転車の現状
<!doctype html>
<html lang="ko">

<head>
    <meta charset="UTF-8">
    <title>JQuery 연습하고 가기!</title>
    <!-- JQuery를 import 합니다 -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <style type="text/css">
        div.question-box {
            margin: 10px 0 20px 0;
        }

        table {
            border: 1px solid;
            border-collapse: collapse;
        }

        td,
        th {
            padding: 10px;
            border: 1px solid;
        }

        .urgent {
            color: red;
        }
    </style>

    <script>
        function q1() {
            $('#names-q1').empty()
            $.ajax({
                type: "GET",
                url: "http://spartacodingclub.shop/sparta_api/seoulbike",
                data: {},
                success: function (response) {
                    let rows = response['getStationList']['row'];
                    for (let i = 0; i<rows.length; i++) {
                        let name = rows[i]['stationName'];
                        let rack = rows[i]['rackTotCnt'];
                        let bike = rows[i]['parkingBikeTotCnt'];

                        let temp_html = ``

                        if (bike < 20) {
                            temp_html = `<tr class = "urgent">
                                            <td>${name}</td>
                                            <td>${rack}</td>
                                            <td>${bike}</td>
                                        </tr>`
                        } else{
                            temp_html = `<tr>
                                            <td>${name}</td>
                                            <td>${rack}</td>
                                            <td>${bike}</td>
                                        </tr>`
                        }

                        $('#names-q1').append(temp_html)
                    }

                }
            })
        }
    </script>

</head>

<body>
    <h1>jQuery + Ajax의 조합을 연습하자!</h1>

    <hr/>

    <div class="question-box">
        <h2>2. 서울시 OpenAPI(실시간 따릉기 현황)를 이용하기</h2>
        <p>모든 위치의 따릉이 현황을 보여주세요</p>
        <p>업데이트 버튼을 누를 때마다 지웠다 새로 씌여져야 합니다.</p>
        <button onclick="q1()">업데이트</button>
        <table>
            <thead>
            <tr>
                <td>거치대 위치</td>
                <td>거치대 수</td>
                <td>현재 거치된 따릉이 수</td>
            </tr>
            </thead>
            <tbody id="names-q1">
            </tbody>
        </table>
    </div>
</body>

</html>
*temp html=```を忘れずに書くようにしましょう("")

apiを受信して写真とテキストを置き換えます

<!doctype html>
<html lang="ko">
    <head>
        <meta charset="UTF-8">
        <title>JQuery 연습하고 가기!</title>
        <!-- JQuery를 import 합니다 -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

        <style type="text/css">
            div.question-box {
                margin: 10px 0 20px 0;
            }

            div.question-box > div {
                margin-top: 30px;
            }

        </style>

        <script>
            function q1() {
                $.ajax({
                type: "GET",
                url: "http://spartacodingclub.shop/sparta_api/rtan",
                data: {},
                success: function (response){
                    let url = response['url']
                    let msg = response['msg']

                    $('#img-rtan').attr("src",url);
                    $('#text-rtan').text(msg);
                        }
                })
            }
        </script>

    </head>
    <body>
    <h1>JQuery+Ajax의 조합을 연습하자!</h1>

    <hr/>

        <div class="question-box">
            <h2>3. 르탄이 API를 이용하기!</h2>
            <p>아래를 르탄이 사진으로 바꿔주세요</p>
            <p>업데이트 버튼을 누를 때마다 지웠다 새로 씌여져야 합니다.</p>
            <button onclick="q1()">르탄이 나와</button>
            <div>
                <img id="img-rtan" width="300" src="http://spartacodingclub.shop/static/images/rtans/SpartaIcon11.png"/>
                <h1 id="text-rtan">나는 ㅇㅇㅇ하는 르탄이!</h1>
            </div>
        </div>
    </body>
</html>
他にもやりたいのですが、画像apiを受信できる場所がないので練習できません.似合わない感じ...

課題<ファン名簿にリアルタイムでソウル天気をアップロード>

<!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/[email protected]/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/[email protected]/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
    crossorigin="anonymous"></script>

    <title>허광한 팬명록</title>

    <style>
       @font-face {
        font-family: 'Amsterdam';
        src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/[email protected]/Amsterdam.woff') format('woff');
        font-weight: normal;
        font-style: normal;
        }
        @font-face {
            font-family: 'Cafe24Oneprettynight';
            src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/[email protected]/Cafe24Oneprettynight.woff') format('woff');
            font-weight: normal;
            font-style: normal;
        }
        .mytitle {
            font-family: 'Cafe24Oneprettynight';
            background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(https://search.pstatic.net/common/?src=http%3A%2F%2Fblogfiles.naver.net%2FMjAyMDAyMTZfMTI1%2FMDAxNTgxODYyMDY0Mzcz.eT3jfREbrjg_iEyXfM1SrlgfE-FphDhB83G0Ij4zOd0g.aWcpioWF6sPhXul9Pigifu3iiulUmibRIKYi_zXgBcog.JPEG.debedebedep%2FIMG_1319.JPG&type=sc960_832);
            background-position: center 45%;
            background-size: cover;
            color: white;
            display: flex;
            height: 400px;
            width: 100%;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
            }
        .mypost {
            font-family: 'Cafe24Oneprettynight';
            max-width: 500px;
            width:95%;
            margin: 20px auto 0px auto;
            box-shadow: 0px 0px 3px 0px gray;
            padding: 20px;
        }
        .mycards {
            font-family: 'Amsterdam';
            max-width: 500px;
            width:95%;
            margin: 20px auto 0px auto;
        }
        .mycards > .card {
            margin: 20px auto;
        }

       .mypost > button {
            margin-top: 10px;
        }
    </style>

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





        function c1() {
            let txt3 = $('#input-q3').val()
            let temp_html = `<li>${txt3}</li>`
            $('#names-q3').append(temp_html)
        }

    </script>

</head>

<body>
    <div class="mytitle">
        <h1>♥허광한 팬명록♥</h1>
        <p>현재 기온: <span id = "temp"></span></p>
    </div>
    <div id = cheeruptxt class="mypost">
        <div class="form-floating mb-3">
          <input type="email" class="form-control" id="floatingInput" placeholder="[email protected]">
          <label for="floatingInput">닉네임</label>
        </div>
        <div class="form-floating">
          <textarea class="form-control" placeholder="Leave a comment here" id="floatingTextarea2" style="height: 100px"></textarea>
          <label for="floatingTextarea2">응원댓글 남기기</label>
        </div>
        <button oneclick = "c1()" type="button" class="btn btn-dark">응원 남기기</button>
    </div>
    <div class = mycards>
        <div class="card">
    <div class="card-body">
        <blockquote class="blockquote mb-0">
            <p>새로나온 신곡도 너무 좋아요!</p>
            <footer class="blockquote-footer">상친니 <cite title="Source Title"></cite></footer>
        </blockquote>
    </div>
   </div>
        <div class="card">
           <div class="card-body">
               <blockquote class="blockquote mb-0">
                   <p>광한아 제발 내한해줘ㅠㅠ </p>
                   <footer class="blockquote-footer">광한바라기 <cite title="Source Title"></cite></footer>
               </blockquote>
           </div>
        </div>
        <div class="card">
           <div class="card-body">
               <blockquote class="blockquote mb-0">
                   <p>노래, 연기 대체 못하는 게 뭐야 우리 광한옵빠!!!</p>
                   <footer class="blockquote-footer">광한빠 <cite title="Source Title"></cite></footer>
               </blockquote>
           </div>
       </div>
    </div>
</body>

</html>
解説ビデオを見ずに自分で作ったので嬉しかったです.
すぐに彼氏と作ったサイトでも今の温度を上げて
間違った山-ソウルは分かれて、フフフ

少し遅れましたが2週間で終了!

3週目にPythonを習います.