【发布时间】:2014-01-01 20:57:24
【问题描述】:
我正在尝试在作为 WebApp 运行的 Google 应用脚本中使用 doGet() 返回 Google 电子表格的标题行。我正在使用 HTML 表单将 GET 请求发送到 WebApp,除了我不知道如何将标头返回到我的 javascript 之外,一切正常。我将发布我的代码:
HTML:
<form id="getForm" method="get" action="My URL for WebApp">
<label for="sheetGetID">SheetID</label>
<input type="text" name="sheetGetID" id="sheetGetID" value="">
<button class="ui-btn" onclick='submitGET()'>Submit</button>
</form>
Javascript:
function submitGET() {
var headers = $("getForm").submit();
alert(headers);
}
谷歌应用脚本:
function doGet(e) {
//Trying To: Get headers from sheetID and then return to app, then have correct labels for the inputs, then use POST to post.
var ss = SpreadsheetApp.openById(ScriptProperties.getProperty('active'));
var sheet = ss.getSheetByName(e.parameter["sheetGetID"]);
//Return the first 3 cells, A1:C1,
var headers = sheet.getRange(1,1,1,sheet.getLastColumn()).getValues()[0];
return ContentService.createTextOutput(JSON.stringify(headers))
.setMimeType(ContentService.MimeType.JSON);
}
我收到了一个 JSON 对象返回,但它只是一个文本输出。我的问题是我将/如何将 JSON 返回并存储为 headers 变量?
【问题讨论】:
标签: javascript json google-apps-script http-get