0

I'm trying to go like author in youtube here

https://www.youtube.com/watch?v=yiPnkBEHqf0&list=PLRmEk9smitaVGAAhgU0Pdc2sEs7yxDrEk&index=2

the task to send data to google spreadsheet from html to spreadsheet

this script I wrote from js with fetch:

const url = "https://script.google.com/macros/s/AKfycbzPNAtqRkYrkbJ8SuDu5mLrtn8A3syzkU7CwzXHUEHXTxJbSLKn/exec";

var loginText = document.getElementById("tLogin");
var tableText = document.getElementById("tTable");
var orderText = document.getElementById("tOrder");

function testGS(){
    var userInfo = {
            login: loginText.value,
            table: tableText.value,
            order: orderText.value,
            tdate: new Date().toLocaleDateString(),
            //komm: kommText.value,
    };

    fetch(url, {
        method: 'POST',
        body: JSON.stringify(userInfo)
      })
      .then((res) => res.text())
      .then((res) => console.log(res));

    }           

document.getElementById("del").addEventListener("click", testGS);


This I wrote in Apps script:

<!-- begin snippet: js hide: false console: true babel: false -->

The html-page is here.

<!doctype html>
<html lang="en">
<head>
<title>CLR: PACKING</title>
<meta charset = "UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="CSS/main_page_style.css">
    <link rel="icon" href="Image/favicon.png" type="png">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet"
       integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">

</head>
<body>
    <div class="conteiner">
        <form novalidate>
                <h6 class="title">PACKING</h6>
                <img src="Image/mainImg.jpg" class="img-fluid" alt="...">
            <div class="dws-input">
                <div class="col-md-3"></div>
                <div>
                    <div>
                        <button id="del" type="button">&lt;======СБРОС</button>
                    </div>
                    <div class="form-floating mb-3 mt-3">
                        <input type="text" class="form-control" novalidate id="tLogin" name= "username" placeholder= "Логин:" autofocus > 
                        <label for="tLogin">Логин:</label>
                    </div>
                    <div class="form-floating mb-3 mt-3">
                        <input type="text" class="form-control" novalidate id="tTable" name= "text" placeholder= "Номер стола:" >
                        <label for="tTable">Номер стола:</label>
                    </div>
                </div>
                <div class="form-floating mb-3 mt-3">
                    <input type="text"  novalidate class="form-control" id="tOrder" name= "text" placeholder= "Заказ:" >
                    <label for="type3">Заказ:</label>
                </div> 
            </div>  
        </form>
    </div>
    <script src="JS/fetchNew.js"></script>

</body>

</html>

Js-script with fetch must be start by clicking button "del" and data must go to spreadsheet. But I take some errors. I have broke my brain, I tryed to reinstall node.js, clasp, tried to login again, prn init, republished my project, but mistake is the same

Can you help me what I forgot? Thank you for help!

The path with spreadsheet is here https://drive.google.com/drive/folders/1JwWgndNrcM2hgxyE3CBF0SKOxZarwCCf?usp=sharing

enter image description here

  • Does this answer your question? [How do i allow a CORS requests in my google script?](https://stackoverflow.com/questions/53433938/how-do-i-allow-a-cors-requests-in-my-google-script) – aaandri98 Aug 04 '21 at 13:10
  • Does this answer your question? [Google App Script Web App GET and POST request blocked by CORS policy](https://stackoverflow.com/questions/56502086/google-app-script-web-app-get-and-post-request-blocked-by-cors-policy) – Iamblichus Aug 04 '21 at 13:18
  • @aaandri98 thank you but I don't think so. I'm junior in this – Dmitriy Rudakov Aug 04 '21 at 13:23
  • @Iamblichus may be, Once Tanaike helped me, but it happened 2 month ago, something I forgot. I will try – Dmitriy Rudakov Aug 04 '21 at 13:25
  • I'm still looking for an answer, I will be glad for any help – Dmitriy Rudakov Aug 09 '21 at 05:06

0 Answers0