首页 > 解决方案 > 响应没有从 Node js 后端返回

问题描述

我从我的 React 应用程序将请求发送到节点 js 后端,但它没有响应请求,它也确认更改。我使用 Redux 和 Redux-Thunk,我想在从后端获得响应后调度一个动作,但后端发生了变化但没有'不响应任何数据,它不起作用。

我想更新用户信息,然后发送一个动作来更新 redux 存储中的数据,但是这个更新只发生在后端,我的意思是在后端更新之后动作不会调度..

ITS MY REACT CODE

export const updateDetails = (name, email, password) => {
  const locals= JSON.parse(localStorage.getItem("user"));
  const token = locals["token"];

  const newDetails = { name, email, password };
  const everyThing = {
    newDetails,
    id: locals["id"],
  };
  const newEvery = JSON.stringify({ everyThing });
  return (dispatch) => {
    dispatch(profileUpdateRequest());
    fetch("users/auth/updateProfile", {
      method: "PUT",
      headers: {
        authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      body: newEvery,
    }) //After That Not Dispatch any action even nothing work
      .then((res) => {
        console.log(res); // Even Doesn't log this
        dispatch(updateProfileUI(newDetails));
      })
      .catch((err) => {
        dispatch(updateProfileFail(err.message));
      });
  };
};

它适用于另一个请求,但不适用于这个请求

标签: javascriptnode.jsreactjsapiredux

解决方案


推荐阅读