下面是一个 Express 程序
问题:: 我没有在 CLIENT 中得到正确的 JSON 响应
我想知道的::
- 当我从客户端发出发布请求时,我是否在服务器(Express)中编写了正确的代码
- 客户端发送请求的形式为
(Key,Value)
客户端以pair - 我确定我遇到了问题的请求结构
我该如何解决?
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'));
});
有任何想法吗?