I am developing a react application which gives information about travel attractions in that country which user selects.
Currently, my app coummnicates to the server with <form>
tag.
This is my react code:
class App extends React.Component{
submitForm = (e)=>{
}
render(){
return(
<div>
<section id="Search" onSubmit={this.submitForm}>
<form action="/public/server/search.php" method="GET">
<input placeholder="search country, attraction names" type="text" name="search"/>
<button type="submit">SEARCH</button>
</form>
</section>
<ItemList/>
</div>
)
}
}
php file: This is just test code. For checking if my php file works.
<?php
$message = "wrong answer";
echo "<script type='text/javascript'>alert('$message');</script>";
?>
There is no problem with the URL.
Problem is when a user submits, the browser downloads php file instead of running it.
I googled and found that if it downloads, there is some problem with my webserver configuration.
Submit button is downloading the php instead of running it
and
But how can I fix the configuration problem whem I am running the file and localhost with npm start? not Apache? or is it same?
I tried to run my file with apache webserver (I already have XAMPP) but it shows 404 error because it doesn't find bundle.js (webpack file).
Here is my package.json file:
{
"name": "ReactExample",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --config ./webpack.config.js --mode
development"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"webpack": "^4.16.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4"
},
"babel": {
"presets": [
"env",
"react",
"stage-2"
]
},
"dependencies": {
"classnames": "^2.2.6",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-redux": "^5.0.7",
"redux": "^4.0.0"
}
}