首页 > 解决方案 > 使用 POST 请求将多个/所有数据从 API 传递到另一个 API

问题描述

我正在尝试将所有记录传递到我在单个 POST 请求中从另一个表中获取的表中,但我觉得我的代码正试图将整个记录作为一个大数据传递。

const [myCart, setMyCart] = useState([])


useEffect(() => {
    axios
      .get("https://localhost:3000/api/cart/")
      .then((res) => {
        setMyCart(res.data)
        console.log(res.data)
      })
  }, []);

  const submitToShip = () => {
      axios
        .post("https://localhost:3000/api/ship/", myCart)
        .then((res) => {
            console.log(res.data)
        })
  }

<button onClick={submitToShip}>Submit</button>

它返回一个错误400,两个表也具有相同的结构

标签: reactjsapiaxios

解决方案


推荐阅读