Toshusai blog

知識の保管庫

JavaScriptのfetchでPOSTリクエストをする

const obj = {title: "This is fetch"};
const options ={
    method: "POST",
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringfy(obj)
}
fetch("https://example.com", options)
    .then((res)=> res.json())
    .catch(console.error);

参考

developer.mozilla.org

https://developer.mozilla.org/ja/docs/Web/API/WindowOrWorkerGlobalScope/fetch