Google apps script 谷歌应用程序脚本doPost不';行不通

Google apps script 谷歌应用程序脚本doPost不';行不通,google-apps-script,Google Apps Script,我试着用谷歌应用程序脚本编写一个BMI HTML网页。但是,doPost始终不会显示结果。 我的代码如下: 代码.gs function doPost(e){ var h= e.parameter.h; var w = e.parameter.w; return HtmlService.createHtmlOutput("bmi="+w/((h*h)/10000)); } function doGet(e) { var t = HtmlService.createTemplateF

我试着用谷歌应用程序脚本编写一个BMI HTML网页。但是,doPost始终不会显示结果。 我的代码如下:

代码.gs

function doPost(e){

 var h= e.parameter.h;
 var w = e.parameter.w;
 return 
HtmlService.createHtmlOutput("bmi="+w/((h*h)/10000));
}

function doGet(e)
{

var t = HtmlService.createTemplateFromFile('Index');
t.serviceUrl = ScriptApp.getService().getUrl();
return t.evaluate();

}
Index.html

<html>
<body>
<form id="bmiForm" action="<?= serviceUrl ?>" method="post">
 <div>height(cm): <input type="text" name="h"/></div>
 <div>weight(kg): <input type="text" name="w"/></div>
 <input type="submit" value="submit"/>
 </form>
 </body>
</html>


已识别此脚本在浏览器控制台中引发的错误-

拒绝在帧中显示“”,因为它将“X-frame-Options”设置为“sameorigin”

解决方案 添加
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
,同时返回
doPost
的HTML输出

请参阅类HtmlOutput

代码.gs Index.html 这是不变的-

<html>

<body>
    <form id="bmiForm" action="<?= serviceUrl ?>" method="post">
        <div>height(cm):
            <input type="text" name="h" />
        </div>
        <div>weight(kg):
            <input type="text" name="w" />
        </div>
        <input type="submit" value="submit" />
    </form>
</body>

</html>


您能否验证是否调用了事件处理程序?如果您不熟悉
google.script.run.function()
client-side API,请使用
console
并将日志发送到Stackdriver(常规
Logger
对于webapp情况将不可靠)。如果您使用的是应用程序脚本Web应用程序、侧栏或对话框,那么这可能是一个更好的选择。如果您的HTML表单不是应用程序脚本Web应用程序,则情况有所不同。如果是这样的话,请告诉我们。
<html>

<body>
    <form id="bmiForm" action="<?= serviceUrl ?>" method="post">
        <div>height(cm):
            <input type="text" name="h" />
        </div>
        <div>weight(kg):
            <input type="text" name="w" />
        </div>
        <input type="submit" value="submit" />
    </form>
</body>

</html>