웹 개발 공부중
ajax 온도 가져오기
redeyes
2021. 12. 14. 15:56
$(document).ready(function (){} = 문서가 준비되면 실행하라는 의미로 이해했는데 , 습관적으로 꼭 넣어주면 좋을거 같다 .
<script>
$(document).ready(function (){
$.ajax({
type : "GET",
url : "http://spartacodingclub.shop/sparta_api/weather/seoul",
data : "",
success(response){
console.log(response['temp']);
let temp = response['temp'];
$('#temp').text(temp);
}
})
});
</script>
그러나 다른 자료나 다른 고수님들을 보면 이거 사용을 피하라는데 정확히 이해는 가지 않는다.
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>서울 온도 가져오기</title>
<script>
$(document).ready(function (){
$.ajax({
type : "GET",
url : "http://spartacodingclub.shop/sparta_api/weather/seoul",
data : "",
success(response){
console.log(response['temp']);
let temp = response['temp'];
$('#temp').text(temp);
}
})
});
</script>
</head>
<body>
<p>현재기온 : <span id="temp">00.0</span></p>
</body>
</html>