Post 为什么在使用Redux存储的获取请求中未定义响应

Post 为什么在使用Redux存储的获取请求中未定义响应,post,redux,response,fetch,Post,Redux,Response,Fetch,我正在编写一个获取请求,以便将新用户发布到应用程序中。fetch与redux存储集成。Response返回[object object],Response.status返回undefined。我是Redux新手,不知道这是否就是错误所在。以下是我的actions creator文件中的代码: export function createCustomerSuccess(values) { return { type: types.CREATE_CUSTOMER_SUCCES

我正在编写一个获取请求,以便将新用户发布到应用程序中。fetch与redux存储集成。Response返回[object object],Response.status返回undefined。我是Redux新手,不知道这是否就是错误所在。以下是我的actions creator文件中的代码:

export function createCustomerSuccess(values) {
    return {
        type: types.CREATE_CUSTOMER_SUCCESS,
        values: values
   };
}

export function createCustomer(values) {
   return function (dispatch, getState) {
       console.log('values passing to store', values);
       return postIndividual(values).then( (response) => { 
           console.log('calling customer actions');
           console.log(response);
           if(response.status === 200){
               console.log(response.status);
               dispatch(createCustomerSuccess(values));
               console.log('create customer success');
           }
           else {
               console.log('not successful');
          }
      });
   };
}


function postIndividual(values) {
    console.log('test from post' + JSON.stringify(values));
    const URLPOST = "http://myurlisworking/Add";
    return fetch (URLPOST, {
        method: "POST",
        headers: {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Access-Control-Origin": "*"
       },
       body: JSON.stringify(values)
   })
  .then(response => response.json())
  .then(response => {
      console.log('response' + response.status)
  });   
}

问题似乎与您的期望有关。当您的第一个
。然后
fetch()
之后被调用时,您将得到
响应。状态可供检查

你可以像下面那样重写你的抓取,看看这是否解决了

function postIndividual(values) {
    console.log('test from post' + JSON.stringify(values));
    const URLPOST = "http://myurlisworking/Add";
    return fetch (URLPOST, {
        method: "POST",
        headers: {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Access-Control-Origin": "*"
       },
       body: JSON.stringify(values)
   })
  .then(response => {
       console.log('response' + response.status)
       return response.ok && response.json();
  })
  .catch(err => console.log('Error:', err));
}
您可以在此处查看
response.status
^并执行所需操作


或者,您也可以在
postIndividual
中执行
fetch
,并在
createCustomer
中处理响应。

感谢您的回复。提取不在后个人函数中解析。当我试图传回createCustomer时,我仍然在createCustomer中得到“未定义”。。。不知道为什么。非常感谢任何其他帮助。@Sizzles27不确定您的意思,代码片段可以帮助我了解您的问题。