I was making a web-based project where the homepage has a button named connect which connects the page to MySQL db via JavaScript, displays an alert saying connected!, and moves to another HTML page. For this, I wrote the following code.
<!DOCTYPE html>
<html>
<body>
<p>Insta-OPD</p>
<button id="myButton">Connect</button>
<script>
document.getElementById("myButton").onclick = function () {
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "qwerty"
});
con.connect(function(err) {
if (err) throw err;
});
alert("done!!!");
location.href = "done.html";
};
</script>
</body>
</html>
It worked well with alert and location.href. But when I added the MySQL connector, nothing was displayed on the screen.
Aucun commentaire:
Enregistrer un commentaire