2016-09-29 133 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 –

相關問題