javascript - 从前端 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);
}
})
})
}
})
解决方案
推荐阅读
- .net - 是什么导致生成的 sql 查询(OData + EF)中出现此随机 GUID
- oracle - 在 Rstudio 中建立与 Oracle DB 的连接
- python - Python 3 中 bisect.insort 的奇怪行为
- html - 搜索栏未正确响应媒体查询
- javascript - JSON 将数字解析为字符串
- css - 我怎样才能弄清楚为什么 Rails Webpacker 正在改变我的 css?
- django - django pk 不适用于 pk 值高于 9
- c# - 使用命名空间 System.Reflection.Emit 将泛型方法作为另一个方法的包装器注入 [C#]
- perl - 如何在 Perl 中用新字符串替换最后一个字符串字符
- python - 如何通过将数字放在文件名的开头来重命名文件