首页 > 解决方案 > 从前端 index.html 运行 nodeJS 函数以发送输入数据

问题描述

我正在寻找有关我的代码的建议,这将有助于我理解呈现 html 和回调托管 index.js 文件中的函数。我目前正在节点服务器中调用一个函数,但我想从一个前端表单传递用户输入的变量,该表单将以相同的方式调用该函数。

我已经可以引用谷歌表格页面并调用 addRow("row#", "{key:index}") 函数,它将输入的变量添加到 excel 页面。如何在实际文档范围之外调用相同的命令?

doc.useServiceAccountAuth(creds, function(err) {

    //get all te rows and shit
    doc.getRows(1, function (err, rows) {
        console.log(rows.length);
    })
//this is a test call of the function which works- I now want to pass it in variables from a user inputted form. 
    submitInfo(doc, 'tabletop fun', 'to have fun', '30', 'will do homework', 'TRUE', '50', 'FALSE')

    //call this when a form is submitted
    function submitInfo(doc, activity, description, time, task_for_completion, experience, amount, completed) {
        doc.getRows(1, function(err, rows) {

            nextRow = rows.length+1;

            doc.addRow(1, { activityID: nextRow, activity: activity, description: description, time: time, task_for_completion: task_for_completion, experience:experience, amount:amount, completed:completed}, function(err) {
                if(err) {
                    console.log(err);

                }
            })
        })
    }
})

http://prntscr.com/o4nhwv

标签: javascriptnode.jsgoogle-api-nodejs-client

解决方案


推荐阅读