简体   繁体   English

简单表单提交重定向到错误的页面,为什么?

[英]Simple form submission redirect to wrong page, why?

I can't understand this behaviour in Google App Script, can someone explain? 我无法理解Google App脚本中的这种行为,有人可以解释吗?

This is a very simple script bound to a Sheet. 这是绑定到图纸的非常简单的脚本。 Code: 码:

Code.js Code.js

function doGet() {
  return HtmlService.createHtmlOutputFromFile("index.html");
}

function doPost() {
  return HtmlService.createHtmlOutputFromFile("index.html");
}

index.html 的index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <form id="form" name="form" action="" method="POST">
      <input type="submit" id="submit" name="submit" value="submit">
    </form>
  </body>
</html>

Looks simple enough right? 看起来足够简单吧? Well when you click the submit button, the page redirect to a blank page. 好吧,当您单击提交按钮时,页面将重定向到空白页面。

I already know how to work around this behavior (by using script.run or even hackier by querying for the page's URL), but what I want is to know WHY things go wrong here, because what's the point of the doPost method if you can't even use it. 我已经知道如何解决此问题(通过使用script.run甚至通过查询页面的URL使用黑客),但是我想知道为什么这里出了问题,因为如果可以的话,doPost方法的重点是什么甚至不使用它。

This is because your page is served from another url *.googleusercontent.com for security reasons. 这是因为出于安全原因,您的网页是从另一个网址*.googleusercontent.com提供的。 The point of doPost method is you can post to the published url from your client(say, local Python script/nodeJs) anywhere on any server as long as you know the published url. doPost方法的要点是,只要知道发布的URL,就可以从任何服务器上的客户端(例如本地Python脚本/ nodeJs)将其发布到发布的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM