React
URL의 html코드를 가져와 출력
green_ne
2020. 7. 17. 19:20
function httpGet(theUrl) {
var xmlHttp = new XMLHttpRequest();
// 3번째 매개변수: true || false
xmlHttp.open("GET", theUrl, false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
function App() {
const url = "https://developer.mozilla.org/ko/docs/Web/HTTP/CORS";
const gethtml = httpGet(url);
console.log(gethtml);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
{gethtml}
</p>
</header>
</div>
);
}
Console과 웹페이지에서 html코드를 확인할 수 있다.
반응형