1

ExpressJSサーバー上Androidでクライアントとして使用しています

サーバーでこのアクションを実行する方法を知りたい::

  • listView大学のリストがあるとJSONします。以下に示す Express プログラムを使用して、このデータを取得します。

  • 今 Android はOnClick、上の位置を識別するために 持っていますlistview

  • AndroidクライアントのJSONを動的に取得する方法(行をクリックすると、JSON URLが動的に生成されるように、サーバー上でデータベースクエリを動的に実行したい)

  • 変更はサーバー側にあると思うので、Androidコードを投稿していませんが、android developers誰が作業したExpressJSNodeJS 、これについてのアイデアも持っています


サーバーでどのようなコード変更を行う必要がありますか?

この機能を実現するには、どのような概念を検討する必要がありますか?


サーバー上の私の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'));
});

私がはっきりしていることを願っています

ありがとう、

4

0 に答える 0