【问题标题】:How to send data with fetch in react-redux如何在 react-redux 中使用 fetch 发送数据
【发布时间】:2018-01-16 22:00:49
【问题描述】:

我正在做一个多复选框过滤器,我必须使用 post 方法向服务器发送一个对象。我如何使用 fetch 来做到这一点?我可以使用 fetch 发送数据吗?我必须从服务器接收过滤列表。 谢谢!

【问题讨论】:

标签: reactjs redux fetch-api


【解决方案1】:

是的,您可以使用 'POST' 指定获取方法

来自https://facebook.github.io/react-native/docs/network.html的示例代码

function getMoviesFromApiAsync() {
    return fetch('https://mywebsite.com/endpoint/', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        firstParam: 'yourValue',
        secondParam: 'yourOtherValue',
      })
    }).then((response) => response.json())
      .then((responseJson) => {
        return responseJson.success;
      })
      .catch((error) => {
        console.error(error);
      });
  }

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 2023-02-21
    • 1970-01-01
    • 2017-09-23
    • 2020-05-01
    • 1970-01-01
    • 2022-07-31
    相关资源
    最近更新 更多