如何合并node.js和html?

时间:2014-10-01 18:06:10

标签: html mysql node.js

我有一个html文件(home.html)和一个node.js文件(app.js)。我也使用了mysql。我现在的app.js是服务器端,如下所示:< / p>

var application_root = __dirname,
    express = require("express"),
    mysql = require('mysql');
    path = require("path");

    var app = express();
    var http = require('http');
    var connection = mysql.createConnection({host : '127.0.0.1',user : 'root', password : '',database: "medical"
});

app.configure(function () {
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(application_root, "public")));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
}); 


 app.get('/getallusers/:email', function (req, res) {
   connection.connect();
     //var json = '';
   connection.query('SELECT * FROM users where email = '+req.params.email, function (error, rows, fields) { 
         str='';
         for(i=0;i<rows.length;i++)
        str = str + rows[i].email +'\n';
//       res.end( str);
            res.end( str);
          //  json = JSON.stringify(rows); //displaying json file
        //res.send(json);
      });
   connection.end(); 
});

在我的home.html中,我有一个文本框和一个代表搜索操作的按钮,用于从数据库中检索数据:

<div class="search" id = "page_content1">
      <h1>Enter Candidate's email: </h1>
      </br>
      <form method="get" action="http://127.0.0.1:1212/getallusers/email">
        <input type="text" name="email" id="email">
        <input type="submit" name="commit" value="search" id = "search" onclick="display()"/>
      </form>
    </div>

现在我想让app.js文件中的查询检索到的结果显示在我的home.html文件中,有关如何操作的任何帮助吗?

0 个答案:

没有答案