2016-09-29 134 views
0

我已经在iFrame中一个简单的形式提交给GAS Web应用程序:消息形式的iFrame提交后,与谷歌脚本的doPost

<form action="https://script.google.com/macros/s/AK...a4/exec" method="POST"> 
    Name:<br> 
    <input type="text" name="name"> 
    <br> 
    Email:<br> 
    <input type="email" name="email" value=""> 
    <br><br> 
    <input type="hidden" name="product" value="Inv"> 
    <input type="submit" value="DOWNLOAD" style="margin:0px auto; display:block; width: 10em; height: 2.4em;"> 
</form> 

我想从的doPost服务发回的iFrame的消息,为例如:

function doPost(e) { 
... 
var response = "<HTML><BODY><H1>Error processing request</H1><BR><BR><P>Missing or invalid parameter in request.</P></BODY></HTML>" 
    return ContentService.createTextOutput(response).setMimeType(ContentService.MimeType.TEXT); 
} 

但是,iFrame在提交后被清空,并且从不显示我的消息。我错过了什么?

谢谢!

回答

0

documentation中所述,使用createTextOutput(content)方法创建可用于给定内容的新对象TextOutput。尝试使用此示例代码:

function doGet() { 
    var output = ContentService.createTextOutput("Hello world!"); 
    return output; 
} 

为了进一步使用你的代码,尝试也是你doPost()函数中删除HTML标签,看看它是否工作。

最后,请检查此SO帖子中给出的解决方案 - HTML Form does not submit to spreadsheet using doPost。它可能也有帮助。

+0

谢谢!我根据您提供的示例链接对GAS中的doGet实施了XMLHttpRequest - 客户端iFrame没有收到任何响应。显然这是谷歌已知的不支持的功能:https://code.google.com/p/google-apps-script-issues/issues/detail?id=1563似乎我没有办法实现双向HTTP沟通在这里... –

+0

我也试着用JSONP实现,但是响应没有通过浏览器,可能是因为谷歌重定向。 https://developers.google.com/apps-script/guides/content#serving_jsonp_in_web_pages –

相关问题