javascript - Google Apps 脚本 google.script.run.withSuccessHandler 失败

标签 javascript jquery google-apps-script

我有 2 个 google.script.run.withSuccessHandler 调用一个接一个发生,当我尝试将两者结合时,它不起作用。这是有效的代码,所有主要内容都受到影响。

//These are in a javascript function which executes when a submit button is clicked.
google.script.run.withSuccessHandler(updateOutput).processForm(frmData);
google.script.run.withSuccessHandler(returnMessage).sendEmail(theData, titles);

//server functions
function processForm(theForm) {
  try{
    var fileBlob1 = theForm.resumeFile;

    var fldrSssn = DriveApp.getFolderById('My Folder ID');
    fldrSssn.createFile(fileBlob1);

    return 'good';
  }catch(e) {

  }//End catch
}

function sendEmail(arr, titles) {
  try {
         //This function sends an email and edits a spreadsheet. Nothing is affected
       return 'Request Submitted';
  }
}

但是当我尝试将两者结合起来时,程序会识别出提交按钮已被单击,但它不会越过 google.script.run.withSuccessHandler 命令。

//google.script.run.withSuccessHandler(updateOutput).processForm(frmData);
google.script.run.withSuccessHandler(returnMessage).sendEmail(theData, titles, frmData);



function sendEmail(arr, titles, theForm) {
  try {

    //Uploads the files
    var fileBlob1 = theForm.resumeFile;

    var fldrSssn = DriveApp.getFolderById('My Folder ID');
    fldrSssn.createFile(fileBlob1);
    var url1;
    //Contains the rest of the code for sending an email and editing a spreadsheet.


    return 'Request Submitted';
  }
}

这是行不通的。有谁知道为什么会失败?当第一个函数成功时调用的函数都只显示一个弹出窗口,告诉用户他们的响应已提交。

最佳答案

来自谷歌文档:

A form element within the page is also legal as a parameter, but it must be the function’s only parameter.

您不能通过表单元素传递任何其他内容,它必须是唯一的参数。

Google Documentation - google.script.run.function(parameter)

关于javascript - Google Apps 脚本 google.script.run.withSuccessHandler 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31192244/

相关文章:

javascript - 在我的案例中如何在指令中分配数据

javascript - Android 工作室 - 调试 Javascript

javascript - 更好地理解 AJAX

jquery - 重新附加 jQuery detach();

javascript - 如何获取 Google App 脚本中所有选中复选框的值

javascript - 编程基于坐标的游戏,例如点或跳棋

javascript - 单击添加新文本时需要调整文本区域的大小

javascript - jQuery 倒计时在日期后继续

javascript - 制作递归函数

google-apps-script - 如何在 Google 表单问题中添加代码片段