Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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
Html 如何在Nodejs中使用POST、GET制作搜索框_Html_Mysql_Sql_Node.js_Parameters - Fatal编程技术网

Html 如何在Nodejs中使用POST、GET制作搜索框

Html 如何在Nodejs中使用POST、GET制作搜索框,html,mysql,sql,node.js,parameters,Html,Mysql,Sql,Node.js,Parameters,我想从表单值发布和获取getparameter关键字,并使用此查询 SELECT * from cider.cid_contents where con_content like \'%'+ keyword +'%\' order by con_no desc; 但我不知道如何从post或form方法中获取关键字值。 有密码 search.js var express = require('express'); var router = express.Router(); var mysq

我想从表单值发布和获取getparameter关键字,并使用此查询

SELECT * from cider.cid_contents 
where con_content like \'%'+ keyword +'%\' 
order by con_no desc;
但我不知道如何从post或form方法中获取关键字值。 有密码

search.js

var express = require('express');
var router = express.Router();
var mysql = require("./model/mysql");

/* GET home page. */
router.post('/search/process', function(req, res, next) {

    var keyword = req.body.keyword;

    console.log(keyword);

    res.redirect('/search');


  });

router.get('/search/:keyword', function(req, res, next) {
    var keyword;
    keyword = req.params.keyword;
    console.log("+++++");
    console.log(keyword+"1234");
    mysql.select('SELECT * from cider.cid_contents where con_content like \'%'+ keyword +'%\' order by con_no desc;',


    function (err, data){
        if (err) throw err;

    res.render('front/search/search', { contents : data});
  });
});


module.exports = router;
这是一个表单标记(top.ejs)


/搜索(search.ejs)


号码
标题
日期
计数
使用主体解析器

var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));

router.post('/search/process', function(req, res, next) {

  console.log(req.body);

});
有关示例,请参见

<table class="bordered">
        <thead>
          <tr>
              <th data-field="no">num</th>
              <th data-field="title">title</th>
              <th data-field="date">date</th>
              <th data-field="viewCount">count</th>
              <th data-field=""></th>
          </tr>
        </thead>
        <tbody>

        <% for(var i = 0; i<contents.length; i++) { %>
            <tr>

                <td><%= contents[i].con_no %></td>
                <td><a href="/adm/contents/detail/<%= contents[i].con_no %>"><%= contents[i].con_title %></a></td>
                <td><%= contents[i].con_regDate %></td>
                <td><%= contents[i].con_viewCount %></td>
                <td><a href="/adm/contents/delete/<%= contents[i].con_no %>">delete</a></td>
            </tr>
        <% } %> 
        </tbody>
      </table>
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));

router.post('/search/process', function(req, res, next) {

  console.log(req.body);

});