Simple login and Change password operation.
Detailed description of the change process
1. First find the data SQL function to be used in the database
BEGIN
DECLARE isin int default (0);
#Routine body goes here ...
Select COUNT (*) into Isin from Ufa_user where account= userName and password= pwd;
If Isin>0 Then
Update ufa_user Set password = pwd1 where account = UserName;
ELSE
select-1;
End If;
END
2. Need two JS, one request, one corresponding.
Server.js Register.js
Important!
2.1 Register needs to link-------------JS, which is local, runs in node environment.
var mysql = require (' mysql2 ');
function Initpool (db) {
return Mysql.createpool ({
host: ' 123.56.179.219 ',
port:3306,
User: ' Root ',
password: ' Yangxiao ',
Database:db,
charset: ' Utf8_unicode_ci ',
Debug:false,
connectionlimit:10
});
}
var mysqlhm =new Map ();
function Initconn (dbname) {
var db = Mysqlhm.get (dbname);
if (!db) {
db = Initpool (dbname);
Mysqlhm.set (dbname,db);
}
return db;
}
String.prototype.format = function ()
{
var args = arguments;
return This.replace (/\{(\d+) \}/g,
function (m,i) {
return args[i];
});
}
/****************************************************/
exports.callmysql=function (DBNAME,QUERY,CB) {
Initconn (dbname). getconnection (function (err,connection) {
if (err) Console.log (err)
console.log (query)
if (connection) {
connection.query (query,function (err,rows,fields) {
if (err) Console.log (err)
try{
CB (rows);
}catch (e) {
CB ([]);
}
connection.release ();
});
}else{
CB ([]);
}
});
};
The link is connected with JS syntax
2.2 Response Process ~ ~
var util = require (".. /util.js ");
Module.exports = function () {
}
2.3 Request Process ~ ~
Defining variables + selecting interfaces
3 Front-End request process
Attention! Contenttxpe must be demanded in Ajax,
ContentType: "Application/json";
A specified port that the URL writes itself, that is, a function in the response function;
Data objects defined previously by Ajax are the PWD in this article
Data:stringify (PWD);
After that, the front end is available for data manipulation.
In Webstrom, you can see the results of node operation and the cause of the error. Equivalent to Dos
Write more complicated tomorrow, and then share it seven o'clock tomorrow night.
Get Started Nodejs