fetch 使用

//最基礎長這樣 

fetch('https://jsonplaceholder.typicode.com/posts')

  .then((response) => response.json())

  .then((json) => console.log(json));


//通常都長這樣 我應該會以這個為基礎去實作 畢竟操作性比較大

fetch('https://jsonplaceholder.typicode.com/posts', {

  method: 'POST',

  body: JSON.stringify({

    title: 'foo',

    body: 'bar',

    userId: 1,

  }),

  headers: {

    'Content-type': 'application/json; charset=UTF-8',

  },

})

  .then((response) => response.json())

  .then((json) => console.log(json));


參考:

https://jsonplaceholder.typicode.com/


留言

這個網誌中的熱門文章

無法載入檔案或組件 'System.IO.Compression' 或其相依性的其中之一。

MongoDB 入門

DDD With MVC