Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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
Javascript 实现搜索功能节点JS/MySQL_Javascript_Mysql_Node.js - Fatal编程技术网

Javascript 实现搜索功能节点JS/MySQL

Javascript 实现搜索功能节点JS/MySQL,javascript,mysql,node.js,Javascript,Mysql,Node.js,在我的节点JS/MySQL-DB上正确实现Pokemon名称的搜索过滤器时遇到了一些问题。当我搜索时,我得到“搜索/?键=未定义404(未找到)”任何想法?这是我的搜索路线 router.get('/search', function(req, res){ var mysql = req.app.get('mysql'); var sql='SELECT pokemonname FROM pokemon WHERE pokemonname LIKE "%' +

在我的节点JS/MySQL-DB上正确实现Pokemon名称的搜索过滤器时遇到了一些问题。当我搜索时,我得到“搜索/?键=未定义404(未找到)”任何想法?这是我的搜索路线

 router.get('/search', function(req, res){
        var mysql =  req.app.get('mysql');
        var sql='SELECT pokemonname FROM pokemon WHERE pokemonname LIKE "%' + req.key.query + '%';
        sql = mysql.pool.query(sql, function(error, results, fields) {
                if(error) {
                   res.write(JSON.stringify(error));
                   res.end();
                } else {
                        res.status(200);
                        res.end();
        }
   });
});
这是我的把手文件,用于渲染搜索栏/搜索按钮

<table id="table">
    <thead>
        <th>Pokemon Name   </th>
        <th>Evolution Level   </th>
        <th>Move Name   </th>
    </thead>
    <input type="text" class="search form-control" id="searchinput" placeholder="Pokemon Name">
    <input type="button" class="btn btn-primary" value="Search" onclick="getUsers({{id}})"/>
        <br>
    <tbody>
        {{#each pokemon}}
        <tr>
            <td>{{pokemonname}}</td>
            <td>{{evolutionlevel}}</td>
            <td>{{movename}}</td>
            <td><button onclick="deletePokemon({{id}})">Delete</td>
        <td><a href="/pokemon/{{id}}">Update</a></td>
        </tr>
        {{/each}}
    </tbody>

感谢您的帮助

大多数出现的
{{id}
都在
#内部使用;每个
循环都建议
id
口袋妖怪
对象的属性。同时,您的
getUser({{id}})
在这个循环之外使用,导致
undefined
传递给绑定变量
id
。我认为您希望将文本输入的值传递给
getUser
函数,因此您需要使用形式参数的名称,例如
searchinput
。您可以从中使用
{{input value=searchinput}}
,然后在按钮中使用
getUser({{searchinput}})
。还要注意传递给被调用的AJAX服务。

大多数出现的
{id}
都在
#内部使用,每个
循环都表明
id
口袋妖怪
对象的属性。同时,您的
getUser({{id}})
在这个循环之外使用,导致
undefined
传递给绑定变量
id
。我认为您希望将文本输入的值传递给
getUser
函数,因此您需要使用形式参数的名称,例如
searchinput
。您可以从中使用
{{input value=searchinput}}
,然后在按钮中使用
getUser({{searchinput}})
。还要注意传递给被调用的AJAX服务

function getUsers(searchinput){
        $.ajax({
                type: 'GET',
                url: '/search/?key=' + searchinput,
                success: function(result){
                        window.location.reload(true);
                }
        })
};