I simply want the php file to "echo $string = 'hello world';" on the html page of my ReactJS app.
But I get this error from my Browser (Google Chrome):
"Unhandled Rejection (SyntaxError): Unexpected token h in JSON at position 0"
Indicating that this is the line causing the issue:
.then((response) => response.json()
My JavaScript:
import React, { Component } from 'react'
import './App.css'
class App extends Component {
componentDidMount(){
fetch('http://localhost/finaldemo.php')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson)
})
}
render () {
return (
<div>
<p> HELLO </p>
</div>
);
}
}
export default App;
My PHP:
<?php header('Access-Control-Allow-Origin: http://localhost:3000');?>
<?php
echo $string = 'hello world';
?>
Where is the problem?
Thanks in advance!