Answer the question
In order to leave comments, you need to log in
Why does it give a 404 error when requesting data?
I'm requesting data from the server, but it gives a 404 error, what's the problem?
Flask:
@app.route('/test', methods=['POST'])
def testing():
test = ['hi']
return jsonify(test)
componentDidMount(){
this.props.getTest('/test')
}
getTest: url =>{
dispatch(test(url))
}
export function testSuccsess(testFiles){
return {
type: 'PERSONS_FETCH_DATA_SUCCESS',
testFiles
}
}
export function test(url){
return (dispatch)=>{
fetch(url)
.then(response =>{
if(!response.ok){
console.log(response)
throw new Error(response.statusText)
}
return response;
})
.then(response=> response.json())
.then(testFiles => dispatch(testSuccsess(testFiles)))
}
}
export default function testing(state = [], action){
switch (action.type) {
case 'PERSONS_FETCH_DATA_SUCCESS':
return action
break;
default:
return state;
}
}
Answer the question
In order to leave comments, you need to log in
As far as I understand, you created a route in Flask with the POST method
. And you send the request in React with the usual GET, which is why you get 404.
https://stackoverflow.com/questions/38510640/how-t...
Can an action be asynchronous? Also for your when the server and front should be running on the same domain and the same port
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question