服务器上的ExpressJS和作为客户端的android 我在服务器上使用ExpressJS,&Android作为客户端
我想知道如何在服务器中执行此操作::服务器上的ExpressJS和作为客户端的android 我在服务器上使用ExpressJS,&Android作为客户端,android,json,node.js,express,Android,Json,Node.js,Express,我想知道如何在服务器中执行此操作:: var express = require('express') , async = require('async') , http = require('http') , mysql = require('mysql'); var app = express(); var connection = mysql.createConnection({ host: 'localhost', user: 'xxx', pa
var express = require('express')
, async = require('async')
, http = require('http')
, mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'xxx',
password: "xxx",
database: 'collages'
});
connection.connect();
// all environments
app.set('port', process.env.PORT || 1232);
//
//REQUEST FOR FIRST REQUEST
//
app.get('/',function(request,response){
var name_of_Collages, RestaurantTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM collagenames', function(err, rows, fields)
{
console.log('Connection result error '+err);
name_of_Collages = 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({
'Collages' : name_of_Collages,
'RestaurantTimings' : RestaurantTimings
});
} );
} );
//
//REQUEST FOR Collage SCREEN
//
app.get('/College1',function(request,response){
var College1, RestaurantTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM College1', function(err, rows, fields)
{
console.log('Connection result error '+err);
College1 = 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({
'College' : College1,
'RestaurantTimings' : RestaurantTimings
});
} );
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
- 假设我有一个大学列表的
,我得到了 使用下面所示的Express程序将其转换为JSONlistView
- 现在安卓已经有了
来识别屏幕上的位置OnClick
listview
- 如何动态获取android客户端的JSON(如果我单击 在一行中,我希望在服务器上动态执行数据库查询 以便动态生成JSON URL)
- 我并没有发布android代码,因为我认为修改是在服务器上进行的
除了与
或ExpressJS
NodeJS一起工作的
我也会有这样的想法android开发者
我需要在服务器上进行哪些代码更改? 实现此功能需要哪些概念?
服务器上的My Express程序::
var express = require('express')
, async = require('async')
, http = require('http')
, mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'xxx',
password: "xxx",
database: 'collages'
});
connection.connect();
// all environments
app.set('port', process.env.PORT || 1232);
//
//REQUEST FOR FIRST REQUEST
//
app.get('/',function(request,response){
var name_of_Collages, RestaurantTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM collagenames', function(err, rows, fields)
{
console.log('Connection result error '+err);
name_of_Collages = 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({
'Collages' : name_of_Collages,
'RestaurantTimings' : RestaurantTimings
});
} );
} );
//
//REQUEST FOR Collage SCREEN
//
app.get('/College1',function(request,response){
var College1, RestaurantTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM College1', function(err, rows, fields)
{
console.log('Connection result error '+err);
College1 = 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({
'College' : College1,
'RestaurantTimings' : RestaurantTimings
});
} );
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
希望我很清楚
谢谢,这个太宽了。。你被困在哪里?似乎您希望其他人按照编写的方式为您编写代码。我已经编写了该代码。。。。很抱歉我是个新手,所以我不擅长技术解释。。。。。。我正在尝试找出如何从android向服务器发送输入。。。。。。。。。。根据这一点,我需要对我的express代码进行哪些更改..感觉你没有四处查看过。谷歌的第一个热门话题: