I am trying to get some data and set a page to be the result
function getData() {
$.ajax({
url:"http://localhost:8080/",
type:'GET',
dataType: 'html',
success: function(data){
console.log(data);
$('.App').html(data);
}
});
}
class App extends Component {
render() {
getData()
return (
<div className="App">This worked</div>
);
}
}
export default App;
This is the response being printed out:
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>React App</title><link href="/static/css/main.c17080f1.css" rel="stylesheet"></head><body><div id="root"><div class="App" data-reactroot=""><header class="App-header"><img src="logo.svg" class="App-logo" alt="logo"/><h1 class="App-title">Welcome to React</h1></header><div></div></div></div><script type="text/javascript" src="/static/js/main.d1b4ad06.js"></script></body></html>
When the page loads, it flashes the correct HTML for a second, then I get this error:
VM11047:1 Uncaught SyntaxError: Unexpected token <
What am I doing wrong?
.html()(which makes up most of the library). You should instead be updating data that causes the react component to render said data once available.