반응형
https://developer.mozilla.org/ko/docs/Web/API/XMLHttpRequest
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HN client</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root">
</div>
<script src="app.js" type="module"></script>
</body>
</html>
const ajax = new XMLHttpRequest();
const RequstType = 'GET';
const NEW_URL = 'https://api.hnpwa.com/v0/news/1.json';
ajax.open(RequstType,NEW_URL,false);
ajax.send();
console.log(ajax.response);
const newFeed = JSON.parse(ajax.response);
const ul = document.createElement('ul');
for(let i = 0; i < 10; i++) {
const li = document.createElement('li');
li.innerHTML = newFeed[i].title;
ul.appendChild(li);
}
document.getElementById('root').appendChild(ul);
// document.getElementById('root').innerHTML = `<ul>
// <li>${newFeed[0].title}</li>
// <li></li>
// <li></li>
// </ul>`;
parsel.js 사용(모듈용)
반응형
'개인공부' 카테고리의 다른 글
맥북 업데이트 후 npm install 에러??(gyp: No Xcode or CLT version detected!) (0) | 2021.06.08 |
---|---|
react build시 경로 못찾을 때 (0) | 2021.06.07 |
git 등록 정보 초기화 (1) | 2021.06.01 |
css : Pure Css Drawing (0) | 2021.05.31 |
AWS 접속포트 열기 (0) | 2021.05.30 |