嘿,我在node.js中全新。
任何人都可以请一步一步地向我解释如何将值显示到下拉列表中..我刚创建一个文件..文件名是fetch.js 以JSON的形式从mysql获取(获取)所有值..这是我的代码..
var http = require('http');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
port : 3306, //port mysql
user : 'root',
password: '',
database: 'node_js'
});
console.log('MySQL Connection details '+connection);
http.createServer(function (request, response)
{
console.log('Creating the http server');
connection.query('SELECT * FROM `emp` where Branch="PHP"', function(err, rows, fields)
{
console.log('Connection result error '+err);
console.log('no of records is '+rows.length);
response.writeHead(200, { 'Content-Type': 'application/json'});
response.end(JSON.stringify(rows));
response.end();
});
}).listen(8084);
我的数据库
CREATE TABLE IF NOT EXISTS `emp` (
`ID` int(5) NOT NULL AUTO_INCREMENT,
`Name` varchar(25) NOT NULL,
`Address` varchar(25) NOT NULL,
`Branch` varchar(25) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
请帮帮我 感谢Adv。