我刚刚在我的网络应用程序中创建了一个 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”,我只希望它只返回我的用户名,但它返回了很多东西 "{"parameter":{"userName":"Leon"},"contextPath":"","contentLength":-1,"queryString":"userName=Leon","parameters":{"userName":[ “莱昂”]}}“
我尝试了参数和参数,doPost(e) 和 doGet(e),都不起作用.. 有人可以帮助我为什么这些不起作用吗?
代码.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
var userName = e.parameter.userName; 返回 HtmlService.createHtmlOutput(userName.toString());