简体   繁体   中英

Simple form submission redirect to wrong page, why?

I can't understand this behaviour in Google App Script, can someone explain?

This is a very simple script bound to a Sheet. Code:

Code.js

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

function doPost() {
  return HtmlService.createHtmlOutputFromFile("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.

This is because your page is served from another url *.googleusercontent.com for security reasons. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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