从url获取参数返回“参数未定义” [英] getting parameters from a url returns 'parameter is undefined"

查看:328
本文介绍了从url获取参数返回“参数未定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,但答案似乎没有我。



我试图通过以下方式将参数传递给脚本:
< a href =https://script.google.com/macros/s/AKfycbzygHQ2qQ.../exec?id=1234&value=Hello =nofollow> https://script.google.com/macros /s/AKfycbzygHQ2qQ.../exec?id=1234&value=Hello



脚本很简单:

 函数doGet(e){
Logger.log('in doGet function');
for(var i in e.parameter){
Logger.log('parameter'+ i + 1 +'is'+ e.parameter [i]);


code


并在执行记录中得到以下内容: p>

  [13-10-01 10:21:20:722 ICT]开始执行
[13-10-01 10 :[21:20:734 ICT] Logger.log([参数未定义,[]])[0秒]
[13-10-01 10:21:20:735 ICT]执行成功[总共0.0秒运行时]

我在这里弄错了什么?

解决方案

简单地使用e.parameter:

 函数doGet(e){
var app = UiApp.createApplication();

var label = app.createLabel('参数值a:'+ e.parameter.a +'参数值b:'+ e.parameter.b);
app.add(label);

返回应用;
}

发布它,

获取网址,您应该获得如下所示的内容:

  https://script.google.com/macros/s/ AKfycbzvmy136r2B1RcIYd7QUmv9-1BBqD9WIwpt3NX9b3Wc3yZJazOj / exec 

在网址中加上?a = Something& b = somethingElse:

  https://script.google.com/macros/s/AKfycbzvmy136r2B1RcIYd7QUmv9-1BBqD9WIwpt3NX9b3Wc3yZJazOj/exec?a=Something&b=somethingElse 

并重新加载页面,您应该看到:

 参数值a:Something  - 参数值b:somethingElse 

在浏览器页面上。


It's a simple question but the answer seems to elude me.

I am trying to pass a parameter to a script in the following way: https://script.google.com/macros/s/AKfycbzygHQ2qQ.../exec?id=1234&value=Hello

The script is a simple one:

function doGet(e) {
  Logger.log('in doGet function');
  for (var i in e.parameter) {
    Logger.log('parameter ' + i+1 + ' is ' + e.parameter[i]);
  } 
}

and getting the following in the execution transcript:

[13-10-01 10:21:20:722 ICT] Starting execution
[13-10-01 10:21:20:734 ICT] Logger.log([parameter is undefined, []]) [0 seconds]
[13-10-01 10:21:20:735 ICT] Execution succeeded [0.0 seconds total runtime]

What did I get wrong here?

Thanks!

解决方案

simply use e.parameter:

function doGet(e) {
  var app = UiApp.createApplication();

  var label = app.createLabel('Parameter value a:'+e.parameter.a+' Parameter value b:'+e.parameter.b);
  app.add(label);

  return app;
}

publish it,

get the URL, you should obtain something like:

https://script.google.com/macros/s/AKfycbzvmy136r2B1RcIYd7QUmv9-1BBqD9WIwpt3NX9b3Wc3yZJazOj/exec

add "?a=Something&b=somethingElse" to the URL:

https://script.google.com/macros/s/AKfycbzvmy136r2B1RcIYd7QUmv9-1BBqD9WIwpt3NX9b3Wc3yZJazOj/exec?a=Something&b=somethingElse 

and reload the page, you should see:

Parameter value a:Something -- Parameter value b:somethingElse

on thw browser page.

这篇关于从url获取参数返回“参数未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆