JavaScript 获取返回 NULL

问题描述 投票:0回答:0

我在这里测试一些东西,我有一个非常基本的 HTML 前端,我将一些数据发送到后端,我正在使用 javascript 获取,我发送一个请求,当我将它保存在数据库中时,值出现作为 NULL ,为什么?

我有以下代码。

<!DOCTYPE html>
<body>
 <button onclick="test()">To Send</button>
<body>

<script>
function test(){
    const data = { name: "Anderson" };
    
    fetch('http://localhost:8081/user', {
        method: 'POST',
        body: JSON.stringify(data),
        headers: {
          'Content-Type': 'application/json'
        }
    }).then(res => res.json())
      .then(data => console.log(data))
      .catch(error => console.log(error))
}
<script>
javascript fetch javascript-objects
© www.soinside.com 2019 - 2024. All rights reserved.