代码之家  ›  专栏  ›  技术社区  ›  Khushdeep Kaur

将Post数据发送到服务器时出错

  •  1
  • Khushdeep Kaur  · 技术社区  · 7 年前

    我正在通过api将数据发送到服务器。但我在响应时得到了错误。

    下面是我的代码

     fetch('http://35.196.195.208/SaveRecommendAppDetails', {
            method: 'POST',
            headers: {              
                     'Content-Type': 'application/json'
                     },
            body: JSON.stringify({
                      UserId:"23",
                      ClientId:"2",
                      Name: "Paras", 
                      Email: "Paras@gmail.com", 
                      Phone: "9876543210",
                      CreatedUserId:"23" ,
                      Company: "Brill Infosystem"})
          })
          .then((response) =>JSON.stringify(response.json())) 
          .then((responseJson) =>{console.log( "==========response=========" + responseJson) })    
          .catch((err) => { console.log("==========error=========" + err); });
        }
    

    错误是: {“_40”:0,“_65”:0,“_55”:null,“_72”:null}

    1 回复  |  直到 7 年前
        1
  •  3
  •   user926721 user926721    7 年前

    { "_40":0,"_65":0,"_55":null,"_72":null } 是当你 console.log Promise 对象这个 response.json() 返回a 许诺 ,所以你不能 JSON.stringify() 它删除对的调用 JSON。stringify() .