我只是在我的网络应用中创建了一个doGet函数,
function doPost(e){
var userName = e.parameter.userName;
return ContentService.createTextOutput(userName);
}
我将它发布给公众,任何人都可以执行它 网址是" https://script.google.com/a/slt.org.au/macros/s/AKfycby2pFGHc3qWaxnD4WGTLMEAPMUocohzH_-OsUPxwqi8kmWfRZs8/exec"
我添加"?userName = Leon"最后
我输入了网址" https://script.google.com/a/slt.org.au/macros/s/AKfycby2pFGHc3qWaxnD4WGTLMEAPMUocohzH_-OsUPxwqi8kmWfRZs8/exec?userName=Leon"最后,我只希望它只返回我的用户名,但它返回了很多东西 " {"参数" {"用户名":"莱昂"}"的contextPath":"&#34 ;," CONTENTLENGTH": - 1,"的queryString":"用户名=莱昂""参数" {"用户名&# 34;:["莱昂&#34]}}"
我尝试了参数和参数,doPost(e)和doGet(e),都没有用。 有人可以帮助我,为什么这些不起作用?
答案 0 :(得分:0)
更改doPost - >的doGet
function doGet(e){
var userName = e.parameter.userName;
return ContentService.createTextOutput(userName);
}
答案 1 :(得分:0)
Codes.gs
function getParams()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Params');
var rg=sh.getDataRange();
var vA=rg.getValues();
var s='<table>';
for(var i=0;i<vA.length;i++)
{
s+=Utilities.formatString('<tr><td>%s</td><td>%s</td></tr>',vA[i][0],vA[i][1]);
}
s+='</table>';
sh.clearContents();
return s;
}
function showTheThisDialog()
{
var ui=HtmlService.createHtmlOutputFromFile('thethisfunc');
SpreadsheetApp.getUi().showModelessDialog(ui, 'The This Func');
}
function doGet(e)
{
var sh=SpreadsheetApp.getActive().getSheetByName('Params');
var ui=HtmlService.createHtmlOutputFromFile('thethisfunc');
var data=e.parameter;
//Logger.log(e.parameter);
for(key in data)
{
var A=[key + ' is a ',data[key]];
sh.appendRow(A);
}
return ui.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
thethisfunc.html
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
google.script.run
.withSuccessHandler(dispParams)
.getParams();
});
function dispParams(hl)
{
console.log(hl);
document.getElementById('mybox').innerHTML=hl;
}
console.log('My Code');
</script>
</head>
<body>
<div id="mybox"></div>
</body>
</html>
这是我的命令行:
https://script.google.com/macros/s/ID/exec?President=Donald&Donald=Duck