获取有问题的反应组件方法

问题描述 投票:0回答:1

我试图在方法(saveUser)中使用fetch进行API CALL。 API工作正常,de方法正在做好他的工作,但我不知道为什么PUT不起作用。

这是代码:

saveUser(user: IUser) {
  user = this.state.user;
  let userId = user._id;
  let url = `http://localhost:4200/api/update-user/${userId}`;

  fetch(url, {
             method: 'put',
             body: JSON.stringify(user),
             headers: {
               'Content-Type': 'application/json'
             }
       }).then(res => res.json())
       .catch(error => console.error('Error:', error))
       .then(response => console.log('Success:', response));
       debugger;
    };

以下是所有代码:manageUserPage

javascript node.js reactjs mongoose
1个回答
0
投票

像这样在request中进行更改:

fetch(url, {
             method: 'PUT',
             body: JSON.stringify(user),
             headers: {
               'Content-Type': 'application/json'
             }

如果问题仍然存在,请确认您已启用CORS。

© www.soinside.com 2019 - 2024. All rights reserved.