數據庫我試圖按照本指南:Google Sheets as a Database – INSERT with Apps Script using POST/GET methods (with ajax example)谷歌表與阿賈克斯
我知道,我已經把「谷歌板/ Apps腳本代碼」中的電子表格。但是我不知道我必須爲Google Apps腳本添加「code.gs」和「index.html」。
因爲stackoverflow示例帶有'form.php'。
HTML
<form id="foo">
<label for="bar">A bar</label>
<input id="bar" name="bar" type="text" value="" />
<input type="submit" value="Send" />
</form>
的JavaScript
// Variable to hold request
var request;
// Bind to the submit event of our form
$("#foo").submit(function(event){
// Abort any pending request
if (request) {
request.abort();
}
// setup some local variables
var $form = $(this);
// Let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
// Serialize the data in the form
var serializedData = $form.serialize();
// Let's disable the inputs for the duration of the Ajax request.
// Note: we disable elements AFTER the form data has been serialized.
// Disabled form elements will not be serialized.
$inputs.prop("disabled", true);
// Fire off the request to /form.php
request = $.ajax({
url: "/form.php",
type: "post",
data: serializedData
});
// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
// Log a message to the console
console.log("Hooray, it worked!");
});
// Callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
// Log the error to the console
console.error(
"The following error occurred: "+
textStatus, errorThrown
);
});
// Callback handler that will be called regardless
// if the request failed or succeeded
request.always(function() {
// Reenable the inputs
$inputs.prop("disabled", false);
});
// Prevent default posting of form
event.preventDefault();
});
form.php的
// You can access the values posted by jQuery.ajax
// through the global variable $_POST, like this:
$bar = $_POST['bar'];
變化由Hawksey
// fire off the request to /form.php
request = $.ajax({
url: "https://script.google.com/macros/s/AKfycbzV--xTooSkBLufMs4AnrCTdwZxVNtycTE4JNtaCze2UijXAg8/exec",
type: "post",
data: serializedData
});
劇本的結尾是讓一種形式,通過郵寄使用AJAX將數據發送到谷歌電子表格。
非常感謝。
請添加更多信息,也許一些代碼。 – Lohardt
我想要做同樣的事情,但帖子沒有指定我要放置的位置和代碼。謝謝。 –
閱讀應用程序腳本官方指南。問題太廣泛。 –