问题描述
鉴于此网址:
https://script.google.com/macros/s/MacroName/dev?theArg =69.28.15.332
最重要的部分是:
?theArg =69.28.15.332
我试图将信息传递给URL中的Apps脚本。
为什么我的 .gs
Google Apps脚本函数不会获取URL末尾的字符串值?这是 doGet(e)
函数。
函数doGet(e ){
var passedInIP = e.parameter.theArg;
Logger.log(passedInIP);
if(passedInIP ===69.28.15.332)
{
return HtmlService.createHtmlOutput(< h2> something< / h2>)
}
};
我在浏览器中输入了这个错误信息:
Logger .log
记录了一些东西。它会记录 [日期时间EDT]69.28.15.332
,并且该值在日志中与我检查的值完全相同。但是平等测试失败。
这个参数是原样传递的,您可以使用下面的代码进行测试:
函数doGet(e){
var passedInIP = e.parameter.theArg;
Logger.log(passedInIP);
if(passedInIP ==69.28.15.332)
{
return HtmlService.createHtmlOutput(< h2> something< / h2>)
}
返回HtmlService.createHtmlOutput(passedInIP)
};
这将返回69.28.15.332
包括引号...
所以你有两种可能性可供选择:
- 删除您网址中的引号
- 在您的条件中添加引号,如''69.28.15.332''(单引号+引号)
我会选择第一个,但没有任何理由; - )
Given this URL:
https://script.google.com/macros/s/MacroName/dev?theArg="69.28.15.332"
The important part is on the end:
?theArg="69.28.15.332"
I'm trying to pass information to an Apps Script in the URL.Why won't my .gs
Google Apps Script function get the value of the string at the end of the URL? This is the doGet(e)
function.
function doGet(e){
var passedInIP = e.parameter.theArg;
Logger.log(passedInIP);
if (passedInIP === "69.28.15.332")
{
return HtmlService.createHtmlOutput("<h2>something</h2>")
}
};
I get this error msg printed in the browser:
The Logger.log
does log something. It logs [Date Time EDT] "69.28.15.332"
and the value is exactly the same in the log, as the value I'm checking for. But the equality test fails.
The argument is passed "as it is", you can test it using a code like below :
function doGet(e){
var passedInIP = e.parameter.theArg;
Logger.log(passedInIP);
if (passedInIP == "69.28.15.332")
{
return HtmlService.createHtmlOutput("<h2>something</h2>")
}
return HtmlService.createHtmlOutput(passedInIP)
};
This will return "69.28.15.332"
including quotes...
So you have 2 possibilities to choose from :
- remove the quotes in your url
- add quotes in your condition like this '"69.28.15.332"' (single quotes+quotes)
I would choose the first one but for no good reason ;-)
这篇关于如何获取传递给Google Apps Script doGet(e)的URL字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!