小编Eko*_*dri的帖子

使用Reactjs的Axios发布表单

因此,我在Axios上使用了这种发布方法,如果我提交了该方法,它会说

未捕获(承诺)错误:XMLHttpRequest.handleError(xhr.js:87)处createError(createError.js:16)出现网络错误

如果我使用这种方法:

axios.post('http://localhost:5000/users', ({userid: this.state.userid})
Run Code Online (Sandbox Code Playgroud)

有用。但是,如果我在axios帖子中添加2个或更多arg,它将再次出错:

axios.post('http://localhost:5000/users', ({userid: this.state.userid}, {fullname: this.state.fullname} ))
Run Code Online (Sandbox Code Playgroud)

这是我的完整代码。如您所见,我尝试使用不同的代码组合,并且只有在我仅传递1个arg的情况下,它才有效。

import React from 'react';
import axios from 'axios';
// import { Form } from 'antd';
// import { List, Card, Form } from 'antd';

export default class FormUser extends React.Component {
    // constructor(props) {
    //   super(props)
    //   this.state = {
      state = {
        userid: '',
        fullname: '',
        usergroup:'',
        emailid: '',
        mobile: '',
        title: '',

  };

  handleChange = event => {
    this.setState({ userid: event.target.value });
    this.setState({ fullname: …
Run Code Online (Sandbox Code Playgroud)

javascript rest post reactjs axios

2
推荐指数
1
解决办法
8853
查看次数

标签 统计

axios ×1

javascript ×1

post ×1

reactjs ×1

rest ×1