HTML
1コード> 引用テキスト
下記URLを参考に作ったのですが、POSTFormでは上手くいくのにGETFormではTypeError:Failed to fetchと表示されます。 ただこの通りにコピペしただけなのですがどこがまちがっていたのでしょうか?
https://tatsuya-note.com/create-database-web-application-in-gas-spreadsheets/](url)
<!DOCTYPE html> <html lang="ja"> <head> <title>GAS Form</title> <style> body{ width: 100vw; height: 100vh; display: flex; flex-direction: row; } #left{ background-color: #ffeeee; width: 50%; display: flex; flex-direction: column; align-items: center; justify-content: start; } #right{ background-color: #eeeeff; width: 50%; display: flex; flex-direction: column; align-items: center; justify-content: start; } </style> <script> function OnPost(){</head> <body> <div id="left"> <h1>POST Form</h1> <p>1列目</p> <input type="text" id="column_1"> <p>2列目</p> <input type="text" id="column_2"> <p>3列目</p> <input type="text" id="column_3"> <p>4列目</p> <input type="text" id="column_4"> <button style="margin-top: 20px;" onclick="OnPost();">送信</button> </div> <div id="right"> <h1>GET Form</h1> <button style="margin-top: 20px;" onclick="OnGet();">取得</button> <p>スプレッドシートの最終行は</p> <p id="get_value"></p> <p>です。</p> </div> </body> </html>const URL = "https://script.google.com/macros/s/AKfycbx4458BgydyTQnaqH_d0JN9XbYtbiashHn1Pn_Edbvu6W16_nbLOsN6SVgE3qizm0RS/exec"; let SendDATA = { "column_1" : document.getElementById("column_1").value, "column_2" : document.getElementById("column_2").value, "column_3" : document.getElementById("column_3").value, "column_4" : document.getElementById("column_4").value }; let postparam = { "method" : "POST", "mode" : "no-cors", "Content-Type" : "application/x-www-form-urlencoded", "body" : JSON.stringify(SendDATA) }; fetch(URL, postparam); } function OnGet(){ const URL = "https://script.google.com/macros/s/AKfycbx4458BgydyTQnaqH_d0JN9XbYtbiashHn1Pn_Edbvu6W16_nbLOsN6SVgE3qizm0RS/exec"; fetch(URL) .then(response => { return response.json(); }) .then(data => { render_text = data.message; document.getElementById("get_value").innerHTML = render_text; }) .catch(error => { document.getElementById("get_value").innerHTML = error; }); } </script>

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/10 01:32
2022/04/10 01:34
退会済みユーザー
2022/04/10 01:43
2022/04/10 14:07
退会済みユーザー
2022/04/10 20:53 編集