Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- es3
- es6
- 퀵정렬
- 브라우저 작동원리
- 알고리즘 문제 풀이
- es6문법
- 주식스팸
- 아키네이처
- HDD와 SSD의 차이
- 1일 1로그 100일 완성 IT지식
- 공개API
- 네트워크해킹
- 숫자구하기
- 데이터분석
- 트위터해킹
- 이진검색
- 아마존해킹
- API요청
- 프로세서 속도와 심장 박동수
- 줌서비스
- ES5
- CS스터디
- 빗썸데이터
- 비전공자개발정리
- 자바스크립트표준
- ES차이
- 한국디도스
- 컴퓨터과학
- ECMA설명
- 컴퓨터 논리와 구조
Archives
- Today
- Total
개발일지
웹개발 종합반 2주차 숙제 - 날씨 API를 이용해서 현재기온 표시 본문
http://localhost:63342/frontend/homework.html?_ijt=22f6athu9eqmmvak08t5r6vu7b&_ij_reload=RELOAD_ON_SAVE

<!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>스파르타코딩클럽 | 부트스트랩 연습하기</title>
<link href="https://fonts.googleapis.com/css2?family=Gowun+Dodum&display=swap" rel="stylesheet">
</head>
<style>
* {
font-family: 'Gowun Dodum', 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://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTetn3r8hsH4FqL4o0f8r8YlikKNvnEQSosjA&usqp=CAU");
background-position: center 30%;
background-size: cover;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.mypost {
max-width: 500px;
width: 95%;
margin: 20px auto 0px auto;
box-shadow: 0px 0px 3px 0px gray;
padding: 20px;
}
.mypost > button {
margin-top: 10px;
}
.mycards {
max-width: 500px;
width: 95%;
margin: 20px auto 0px auto;
}
.mycards > .card {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
let temp = response['temp']
$('#temp').text(temp)
}
})
});
</script>
<body>
<div class="mytitle">
<h1>10cm 팬명록⭐</h1>
<p>현재기온 : <span id ="temp">00.0도</span></p>
</div>
<div class="mypost">
<div class="form-floating mb-3">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<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 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">호빵맨</footer>
</blockquote>
</div>
</div>
<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>새로운 앨범 너무 멋져요!</p>
<footer class="blockquote-footer">호빵맨</footer>
</blockquote>
</div>
</div>
<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>새로운 앨범 너무 멋져요!</p>
<footer class="blockquote-footer">호빵맨</footer>
</blockquote>
</div>
</div>
</div>
</body>
</html>
숙제 코드 - 날씨 API 부분
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
let temp = response['temp']
$('#temp').text(temp)
}
})
});
</script>
해당 api url로 변경하고 처음 이해가 잘 되지 않을때는 하나 하나씩 사이트 우클릭 검사를 통해서
console.log(response)로 먼저 API 결과값을 확인해보고
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
console.log(temp)
}
})
});
</script>

필요한 temp를 불러온다
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
let temp = response['temp']
console.log(temp)
}
})
});
</script>

확인 후 텍스트바꾸기 코드를 적용하며 사이트 확인.
- 이미지 바꾸기 : $("#아이디값").attr("src", 이미지URL);
- 텍스트 바꾸기 : $("#아이디값").text("바꾸고 싶은 텍스트");
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
let temp = response['temp']
$('#temp').text(temp)
}
})
});
</script>
'강의 > 웹개발 종합반' 카테고리의 다른 글
웹개발 종합반 5주차 숙제 - 개발일지 쓰기 (0) | 2022.04.17 |
---|---|
웹개발 종합반 4주차 숙제 - 팬명록 완성 (0) | 2022.04.14 |
웹개발 종합반 3주차 숙제 - 지니 뮤직 크롤링하기 (0) | 2022.04.12 |
웹개발 종합반 1주차 숙제 - 10cm 팬명록 만들기 (0) | 2022.04.08 |