음... 지난 주에 진즉에 2주차 숙제까지 끝내놨는데, WIL를 아직 작성을 못해서, 3주차로 못넘어 가고 있다.
Ajax 기본 골격
$.ajax({
type: "GET",
url: "여기에URL을입력",
data: {},
success: function(response){
console.log(response)
}
})
Ajax 코드 해설
$.ajax({
type: "GET", // GET 방식으로 요청한다.
url: "http://spartacodingclub.shop/sparta_api/seoulair",
data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
success: function(response){ // 서버에서 준 결과를 response라는 변수에 담음
console.log(response) // 서버에서 준 결과를 이용해서 나머지 코드를 작성
}
})
$ajax 코드 설명
- type: "GET" → GET 방식으로 요청한다.
- url: 요청할 url
- data: 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
GET 요청은, url뒤에 아래와 같이 붙여서 데이터를 가져갑니다.
ex) http://naver.com?param=value¶m2=value2
POST 요청은, data : {} 에 넣어서 데이터를 가져갑니다.
data: { param: 'value', param2: 'value2' },
- success: 성공하면, response 값에 서버의 결과 값을 담아서 함수를 실행.
참고할 만한 레퍼런스들
https://www.w3schools.com/jquery/jquery_ref_overview.asp
특이사항(아이디어, 메모 등)
지시사항 및 고객 요구사항(숙제?)
<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>
회고(반성 또는 피드백 받은 것)
중간중간 작업하던걸 끊어가며 하는 상황이라.. 머릿속이 빙글빙글...
그냥 강의는 한번 쭉 듣고.. 다시 듣고 해야지..ㅠㅠ
To-do list
뜬금 없지만, Github 프로필 꾸미기 해보고 싶어졌다..(응?)