我是django和reactjs的新手,我尝试使用axios进行POST请求,但无法发送数据。我收到控制台错误
POST http://localhost:8000/api/todos/ 400(错误请求)
这是我的package.json
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000/",
"secure": false,
"dependencies": {
"axios": "^0.18.0",
"bootstrap": "^4.3.1",
"moment": "^2.24.0",
"react": "^16.5.2",
"react-datepicker": "^2.5.0",
"react-datetime": "^2.16.3",
"react-datetime-picker": "^2.4.0",
"react-dom": "^16.5.2",
"react-scripts": "2.0.5",
"reactstrap": "^6.5.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
这是我正在使用axios的App.js
refreshList = () => {
axios
// .get("/api/todos/", {
// headers: {
// 'Content-Type': 'application/json',
// "Access-Control-Allow-Origin": "*"
// }
// })
.get("http://localhost:8000/api/todos/", { headers: {
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*"
}
})
.then(res => this.setState({ todoList: res.data }))
.catch(err => console.log(err));
};
答案 0 :(得分:0)
如果您控制台记录响应状态,它应该为您提供更详细的错误描述。
示例:
if(response) {
console.log(response.status)
}