reactjs - 无法发送发布请求
问题描述
我正在尝试通过发布请求使用 axios 在 ReactJS 中发送数据。问题是当我发送数据时,它会出现在我的 url 中,例如“ http://127.0.0.1:8000/Sessions/11?courses=2018-09-30 ”,但我希望它进入我的数据库。
我的要求是这样的:
AddCourses (courses) {
axios.request({
method: 'post',
url: `http://127.0.0.1:8000/api/sessions/${session_id}/courses`,
data: courses,
headers: {'Content-Type': 'application/json' , 'Accept':
'application/json' , 'Authorization': `Bearer
${authentication.getToken()}`}
}).catch(err => console.log(err))
}
onSubmit (event) {
let session_id = this.props.match.params.id
const newCourses = {
date: this.refs.date.value,
}
this.AddCourses(newCourses)
event.preventDefault(
this.props.history.push(`/Courses`),
)
}
我的道具在我的路由器中是这样定义的:
<Route path="/Sessions" exact component={Sessions}/>
<Route path="/Sessions/:id" exact render={props =>
<GeekSessions{...props} /> }/>
在我的组件中,我有另一个发布请求,当我测试它时,我有错误'Uncaught TypeError:无法读取未定义的属性'props'
我无法弄清楚这两个问题。如果您有任何解决方案,这将非常酷。感谢你们。
解决方案
推荐阅读
- azure-active-directory - CefSharp 浏览器控件不适用于 Azure AD 条件访问
- python - tkinter 按钮命令在迭代中无法正常工作
- python - Pip 不使用垫片,但系统 'pip' 用于 pyenv
- javascript - 如何在 ES6 JS 中向类外部添加方法
- architecture - 如何确定软件项目采用哪种架构风格?
- python - Qt中GraphicsScene的拖拽和鼠标移动事件分离
- windows - 如何通过 C++ 在 Windows 中提取文件图标?
- reactjs - React API 调用 QuickBase 以选择 LineCharts 的多个数据点
- html - 将由 div 包裹的多层画布居中
- amazon-web-services - 在 aws lite ubnutu 服务器中不允许操作