티스토리 뷰
참고! Ajax는 jQuery를 임포트한 페이지에서만 동작 가능합니다.
즉, http://google.com/ 과 같은 화면에서 개발자도구를 열면,
jQuery가 임포트 되어있지 않기 때문에 아래와 같은 에러가 뜹니다.
Uncaught TypeError: $.ajax is not a function → ajax라는 게 없다는 뜻
$.ajax({
type: "GET", // GET 방식으로 요청한다.
url: "<http://spartacodingclub.shop/sparta_api/seoulair>",
data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
success: function(response){ // 서버에서 준 결과를 response라는 변수에 담음
console.log(response) // 서버에서 준 결과를 이용해서 나머지 코드를 작성
}
})
ajax기본 골격
$.ajax({
type: "GET",
url: "여기에URL을입력",
data: {},
success: function(response){
console.log(response)
}
})
ex)
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
let temp = response['temp']
$('#seoultemp').text(temp)
}
});
'Learned!' 카테고리의 다른 글
221210 댓글기능 구현 (0) | 2022.12.10 |
---|---|
221207 pymongo사용시 TypeError: 'Collection' object is not callable 에러 (0) | 2022.12.08 |
[wip]221206~ 깃허브 원격저장소에 있는 변경사항 가져올때 conflict (0) | 2022.12.06 |
221205 회원가입 유효성 검사 코드를 만들 때 (0) | 2022.12.05 |
220915 HTML (0) | 2022.09.15 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Lock
- jmeter부하테스트
- jmeter로그인
- EC2
- jmeter쿠키
- jwt
- 프로그래머스
- jmeter시나리오
- bankersRounding
- Redisson
- 토큰
- Python
- hackerrank
- CheckedException
- jmeter테스트
- pessimisticlock
- 대규모더미데이터
- jmeter세션
- index
- 부하테스트시나리오
- 자바
- 인덱스
- CorrectnessAndTheLoopInvariant
- Java
- jmeter토큰
- 항해
- Spring
- 동적크롤링
- Redis
- 스프링faker
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함