Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务器上的ExpressJS和作为客户端的android 我在服务器上使用ExpressJS,&Android作为客户端_Android_Json_Node.js_Express - Fatal编程技术网

服务器上的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'));
});
  • 假设我有一个大学列表的
    listView
    ,我得到了 使用下面所示的Express程序将其转换为JSON

  • 现在安卓已经有了
    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代码进行哪些更改..感觉你没有四处查看过。谷歌的第一个热门话题: