我有一个数据库,其中存储了登录我网站的所有用户,并希望他们能够删除他们的帐户。所以我做了一个可以工作的函数,可以删除用户的 accs,但我遇到的唯一问题是我似乎无法将具有按钮事件侦听器的 js 文件与我的 nodejs 文件与该函数连接.
// node.js file
let id = 1;
/* delete user from mysql db */
async function delUsers() {
/* actually hardcoded id, need to implement users id when a user can login into the site */
await pool.query('DELETE FROM user WHERE id = ?', [id]);
console.log("Deleting..");
};
// js file
'use strict';
console.log('linked');
let del = document.getElementById('delbutton').addEventListener('click', Del);
let a = require('./delete.js');
function Del() {
let b = a.DelUser();
}
我尝试将 module.exports 与 module.import、require、sessionstorage、localstorage 一起使用。我希望我的按钮能够正常工作并删除我的 1 位用户
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
nodejs 用于后端。
全局对象“window, document...”仅包含在浏览器中。