Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyya8403 authored Oct 13, 2024
1 parent 36356ca commit e58e51a
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,35 @@ Quagga.onDetected(function(data) {
// ビープ音を再生
beepSound.play();

const spreadsheetUrl = "https://script.google.com/macros/s/AKfycbwKHDeDREhoT6ABo0D6MirpHosuKz0fJlboXned3NJBI-JqUXSp-0BSt5xj5jVd-gWb/exec"; // デプロイURLを設定

function sendBarcode(barcode) {
const xhr = new XMLHttpRequest();
xhr.open("POST", spreadsheetUrl, true); // 非同期リクエスト
xhr.setRequestHeader("Content-Type", "application/json");

xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { // 完了したとき
if (xhr.status === 200) {
console.log("スプレッドシートに送信成功:", xhr.responseText);
} else {
console.error("スプレッドシートへの送信に失敗:", xhr.statusText);
}
fetch(spreadsheetUrl, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ barcode: barcode })
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTPエラー: ${response.status}`);
}
};

const data = JSON.stringify({ barcode: barcode });
xhr.send(data);
return response.json();
})
.then(data => {
console.log("スプレッドシートに送信成功:", data);
})
.catch(error => {
console.error("スプレッドシートへの送信に失敗:", error);
});
}

// テスト: バーコードを送信
sendBarcode("123456789");



// 読み取り成功のアニメーション(背景色のフラッシュ)
document.body.classList.add('flash');
setTimeout(function() {
Expand Down

0 comments on commit e58e51a

Please sign in to comment.