Make a button in html delete a row in MySql
P粉760675452
P粉760675452 2024-04-01 13:24:27
0
1
340

I am currently working on a project where I use nodejs to create a user and add the user to MySql in a table called "users" I want to create a button in html that deletes the currently logged in user from mysql table

How do I make a button in html call a function in nodejs to delete a row in MySql

P粉760675452
P粉760675452

reply all (1)
P粉762447363

This might be a good start to understand how to trigger API calls from Js

fetch('https://reqres.in/api/deleteUser', { method: "DELETE", headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ id: '1' }) }) .then(res => { if (res.ok) { console.log("HTTP request successful") } else { console.log("HTTP request unsuccessful") } return res }) .then(res => res.json()) .then(data => console.log(data)) .catch(error => console.log(error))

Then NodeJs

// Module dependencies var express = require('express'), ejs = require('ejs'), fs = require('fs'), mysql = require('mysql'); // Application initialization var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '' //
           
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!