从前端index.html运行nodeJS函数以发送输入数据

时间:2019-06-21 02:40:12

标签: javascript node.js google-api-nodejs-client

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

我已经可以引用Google表格页面并调用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

0 个答案:

没有答案