您可以使用来访问GET在
doGet(e)函数中传递的参数
e.parameter。如果您致电
http://script.google......./exec?method=doSomething,
function doGet(e) { Logger.log(e.parameter.method);}doSomething在这种情况下,将被写入日志。
可以使用ContentService从脚本返回数据,该服务允许您提供JSON(我建议)。在我看来,JSON最容易在GAS端以及在客户端使用。
最初的“填充列表”调用看起来像这样。我会用jQuery编写它,因为我觉得这很干净。
var script_URL = "http://script.google.com/[....PUT YOUR script URL HERE....]/exec";$(document).ready(function() { $.getJSON(script_URL+"?callback=?", {method:"populate_list"}, function (data) { alert(JSON.stringify(data)); });});以及产生此结果的相应GAS。
function doGet(e) { if (e.parameter.method=="populate_list") { var v = {cat:true,dog:false,meow:[1,2,3,4,5,6,4]}; //could be any value that you want to return return ContentService.createTextOutput(e.parameter.callback + "(" + JSON.stringify(v) + ")") .setMimeType(ContentService.MimeType.JAVAscript); }}此方法称为JSONP,jQuery支持。当您
?callback=?在URL后面加上时,jQuery会识别它。它将您的输出包装在回调函数中,该函数允许将该函数以数据作为参数在您的站点上运行。在这种情况下,回调函数是在读取行中定义的函数
function(data) {。


