ExpressJS在服务器上和android作为客户端

时间:2013-08-27 03:36:05

标签: android json node.js express

我在服务器&上使用ExpressJS Android作为客户

我想知道如何在server ::

中执行此操作
  • 假设我有一个listView的大学名单,我会得到数据 这是JSON使用下面显示的Express程序。

  • 现在Android已经OnClick用于识别该位置 listview

  • 如何动态获取Android客户端的JSON(如果我点击 在一行中,我想在服务器上动态地进行数据库查询 以便动态生成JSON URL

  • 我没有发布Android代码,因为我认为修改是在服务器上 与android developersExpressJS合作的NodeJS方 也会对此有一个想法


我需要在服务器上进行哪些代码更改?

我需要了解哪些概念才能实现此功能?


服务器上的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'));
});

希望我很清楚

谢谢,

0 个答案:

没有答案