问题:: 我没有在客户端获得正确的JSON响应
我想知道什么::
(Key,Value)
对我如何解决?
var express = require('express')
, async = require('async')
, http = require('http')
, mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: '*************',
password: "**************",
database: 'restaurants'
});
connection.connect();
// all environments
app.set('port', process.env.PORT || 1828);
app.get('/RestaurantDesc/:Key',function(request,response,next){
var keyName=request.params.Key;
var name_of_restaurants, RestaurantTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM ',keyName, function(err, rows, fields)
{
console.log('Connection result error '+err);
name_of_restaurants = rows;
callback();
});
},
// Get the second table contents
function ( callback ) {
connection.query('SELECT * FROM RestaurantTimings', function(err, rows, fields)
{
console.log('Connection result error '+err);
RestaurantTimings = rows;
callback();
});
}
// Send the response
], function ( error, results ) {
response.json({
'restaurants' : name_of_restaurants,
'RestaurantTimings' : RestaurantTimings
});
} );
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
任何想法?
答案 0 :(得分:1)
您没有处理POST请求的路由。你应该有类似app.post('/route', function(request, response, next) { ... });
的东西。
您还需要使用Express正文解析器从POST请求中获取数据,即app.use(express.bodyParser());
。然后,您可以在中间件功能中访问request.body
中的数据。