티스토리 뷰
728x90
async function doAjaxThings() {
// await code here
let result = await makeRequest("GET", url);
// code below here will only execute when await makeRequest() finished loading
console.log(result);
}
document.addEventListener("DOMContentLoaded", function () {
doAjaxThings();
// create and manipulate your DOM here. doAjaxThings() will run asynchronously and not block your DOM rendering
document.createElement("...");
document.getElementById("...").addEventListener(...);
});
function makeRequest(method, url) {
return new Promise(function (resolve, reject) {
let xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send();
});
}
728x90
'공부' 카테고리의 다른 글
[JavaScript] remove tags (0) | 2021.11.29 |
---|---|
[Linux] download wget `url` (0) | 2021.11.28 |
[NewAutoReplyBot-Helper] API (0) | 2021.11.28 |
[Java] HashMap initialize directly (0) | 2021.11.28 |
[Java] String[] strings = list.toArray(String[]::new); (0) | 2021.11.27 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 어떻게 능력을 보여줄 것인가?
- 테슬라 레퍼럴
- 인스타그램
- 김달
- 테슬라 리퍼럴 코드 혜택
- 모델 Y 레퍼럴
- 테슬라
- 개리마커스
- 클루지
- 메디파크 내과 전문의 의학박사 김영수
- Kluge
- Bot
- wlw
- 테슬라 레퍼럴 코드 확인
- 테슬라 레퍼럴 적용 확인
- 유투브
- follower
- COUNT
- 레퍼럴
- 책그림
- 연애학개론
- 테슬라 크레딧 사용
- 팔로워 수 세기
- 테슬라 리퍼럴 코드 생성
- 모델y
- 할인
- 테슬라 추천
- 테슬라 리퍼럴 코드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함