问题::我在CLIENT中没有得到正确的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'));
});
有任何想法吗?
您没有处理POST请求的路由。你应该有类似的东西app.post('/route', function(request, response, next) { ... });
。
您还需要使用Express正文解析器从POST请求(即)中获取数据app.use(express.bodyParser());
。然后,您可以request.body
在中间件功能中访问数据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句