-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.html
35 lines (31 loc) · 1.01 KB
/
fetch.html
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
32
33
34
35
<!DOCTYPE html>
<html>
<body>
<article>
</article>
<input type="button" name="" value="fetch" onclick="
/*
fetch('css').then(function(response){
response.text().then(function(text){
//alert(text); //알림메세지
document.querySelector('article').innerHTML = text; //article 내용 변경
});
});
*/
//fetch('css'); //첫 인자로 전달된 데이터를 서버에 요청
//Asynchronous 비동기
function callbackme(){
console.log('response end');
}
fetch('css').then(callbackme);//then -> 응답요청 후 대기하지 않고 나머지 함수 실행, 요청 완료되면 그때 함수 콜백
console.log(1);
console.log(2);
fetch('csss').then(function(response){ //없는 파일 요청
console.log(response.status); //응답 코드 확인
if(response.status == '404'){ //404 not found라면
alert('not found');
}
});
">
</body>
</html>