Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Axios未捕获(承诺中)错误:请求失败,状态代码404_Reactjs_Api_Rest_Post_Axios - Fatal编程技术网

Reactjs Axios未捕获(承诺中)错误:请求失败,状态代码404

Reactjs Axios未捕获(承诺中)错误:请求失败,状态代码404,reactjs,api,rest,post,axios,Reactjs,Api,Rest,Post,Axios,我需要将数据发送到后端,但出现以下错误: 未捕获(承诺中)错误:请求失败,状态代码404 我如何解决这个问题?? 下图: 代码如下: handleClick(_success, _error) { const usuarioLogin = this.props.cliente; const usuarioCliente = parseInt(this.state.usuario); const ObjetoChamado = { titulo: this.

我需要将数据发送到后端,但出现以下错误:

未捕获(承诺中)错误:请求失败,状态代码404

我如何解决这个问题??

下图:

代码如下:

handleClick(_success, _error) {
    const usuarioLogin = this.props.cliente;
    const usuarioCliente = parseInt(this.state.usuario);

    const ObjetoChamado = {
      titulo: this.state.titulo,
      descricao: this.state.descricao,
      area: parseInt(this.state.area),
      categoria: parseInt(this.state.categoria),
      servico: parseInt(this.state.servico),
      usuario: usuarioLogin,
      cliente: usuarioCliente,
    };

    this.props.abrirChamado(
      ObjetoChamado,
      (response) => {
        this.props.getChamados(usuarioLogin, null, (chamados) => {
          // Chamado aberto, atualizar lista e fechar o popup de abertura
          this.props.setClientData(usuarioLogin, null, chamados.data.objeto);
          this.props.visible(false);
        });
      },
      (error) => {
        alert(!!error ? error : 'Não foi possível abrir o chamado.');
      }
    );

    axios.post(ObjetoChamado).then((response) => {
      const data = response.data;

      //   if (Object.keys(data).length > 0) {
      //     if (typeof _success === 'function') _success(data);
      //   } else {
      //     if (typeof _error === 'function') {
      //       _error({
      //         code: 404,
      //         message: 'Não há nenhum registro para este cliente.',
      //       });
      //     }
      //   }
      console.log('DATA:', data);
    });
  };

状态代码404表示您在axios中提供的API路径无效。因此,您需要检查API路径

这是错误的

您需要向axios.post传递两个参数,第一个参数是要发送数据的API路径,第二个参数是数据对象。 所以你的代码看起来像这样-

post('/your-api path',objectoChamado)。然后(response=>{


}))

状态代码404表示您在axios中提供的API路径无效。因此,您需要检查API路径

这是错误的

您需要向axios.post传递两个参数,第一个参数是要发送数据的API路径,第二个参数是数据对象。 所以你的代码看起来像这样-

post('/your-api path',objectoChamado)。然后(response=>{

}))