This article needs to use node.js to make a small function to obtain data from Sqlserver and display it on the page. Here is a share with you:
app.js:
var sqlbll = require('./routes/sqlbll'); ... app.get('/sqlbll/:ver', function(req, res){ var versionId=req.params.ver; //sqlbll.getData is the method to get data in the route, //Write the second parameter as a callback function here. sqlbll.getData(versionId,function(data){ res.json(data); //Send json data}); }); //Here is the routing file ====sqlbll.js==== ... exports.getData = function(ver,back){ //...The method of obtaining sql data is omitted here 1000 words back(jsondata) }Next, just use the get method to request it directly on the page, and of course the post method is similar.
var expression = require('express'); var app = express(); app.configure(function() { //By default Express does not know how to handle the request body, so we need to add bodyParser middleware to analyze //application/x-www-form-urlencoded and application/json //request body, and store variables into req.body. We can "use" the middleware as follows [this ensures that POST can get the value of the request parameter]: app.use(express.bodyParser());}); //handle POST request //name and email are the parameter names in the POST request field app.post('/hello', function(req, res) {.......});I also found that when the textarea control changes its text and html properties, the value still maintains the original value.
This feature made me incredible for a while.
Let me share another example with you. nodejs obtains specific data table information , the specific content is as follows
var mysql = require('mysql');var conn = mysql.createConnection({ host: 'localhost', user: 'root', password: '123456', database:'mysql', port: 3306});var tempArr = new Array(); connect();conn.query("show tables",function(err,results){ if(err) { throw err; } if(results){ for(var i = 0; i < results.length; i++) { tempArr[i] = results[i]; var a = tempArr[i]; console.log(typeof(results[i])); console.log(a); var temp = ""; temp+=a.Tables_in_mysql; console.log("temp"+i+" "+temp); conn.query("select * from"+ " "+ temp,function selectCb(err,result,fields){ if(err) { throw err; } console.log("Data table:" + results[i]); console.log(fields); }); }} })The above is all about this article, I hope it will be helpful to everyone's learning.