I have the following programs, test.html and test.php
test.html:
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class NameForm extends React.Component {
componentDidMount(){
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
console.log(xmlHttp.responseText)
}
}.bind(this)
xmlHttp.open("GET","test.php",true)
xmlHttp.send(null)
event.preventDefault()
}
render() {
return (<div/>)
}
}
ReactDOM.render(
<NameForm />,
document.getElementById('root')
);
</script>
</body>
test.php
<?php
echo "this is a test"
?>
When I open the html page I get the content of the php script written in the console rather than the result of running the php script as I was expecting, that is to say, in the console I get this:
<?php
echo "this is a test"
?>
rather than this:
this is a test
Why is this? How can I fix it? Thanks,
Also in case this is relavent I am running this locally using python SimpleHTTPServer