Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.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
node.js中按钮的Post值_Node.js_Post - Fatal编程技术网

node.js中按钮的Post值

node.js中按钮的Post值,node.js,post,Node.js,Post,我有一个表单提交一个查询,最终将在MySQL中执行 但是,我在发布按钮的文本值时遇到了一个问题。我有一个下拉按钮,允许查询模式,我需要能够在node.js post方法中访问它。当试图访问id为“searchmethod”的按钮的文本或值时,它会崩溃,说按钮未定义,但是,我的文本框返回post很好 编辑: TypeError:无法在route.dispatch(/root/Folder/node\modules/express/lib/router/route.js:103:13)的下一层(/r

我有一个表单提交一个查询,最终将在MySQL中执行

但是,我在发布按钮的文本值时遇到了一个问题。我有一个下拉按钮,允许查询模式,我需要能够在node.js post方法中访问它。当试图访问id为“searchmethod”的按钮的文本或值时,它会崩溃,说按钮未定义,但是,我的文本框返回post很好

编辑: TypeError:无法在route.dispatch(/root/Folder/node\modules/express/lib/router/route.js:103:13)的下一层(/root/Folder/node\modules/express/lib/router/route.js:107:5)的c(/root/Folder/node\modules/express/lib/router/index.js:195:24)读取未定义的Object.handle(/root/Folder/Folder/router/router/route.js/route.js:15:50)的属性“值”在Function.proto.process_参数(/root/Folder/node_modules/express/lib/router/index.js:251:12)在next(/root/Folder/node_modules/express/lib/router/index.js:189:19)在next_层(/root/Folder/node_modules/express/router/route.js:77:14)在next_层(/root/Folder/node_modules/express/lib/router/router/route.js:81:14)在next_层(/root/Folder/node_modules/express/lib/router/route.js:81:14)在route.dispatch(/root/Folder/node_modules/express/lib/router/route.js:107:5)

按钮/表单的HTML

<form method="post" action="/" class="box">
            <h3 style="color:#5F5F5F">Inventory Item Lookup</h3>
            <div class="input-group dropdown">
                <div class="input-group-btn">
                    <button name="searchmethod" id="search-button" type="button" class="btn btn-default">Name</button>
                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                        <span class="caret"></span>
                        <span class="sr-only">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li class="drop-list-item"><a href="#">Name</a></li>
                        <li class="drop-list-item"><a href="#">Manufacturer</a></li>
                        <li class="drop-list-item"><a href="#">Description</a></li>
                        <li class="drop-list-item"><a href="#">Location</a></li>
                        <li class="divider"></li>
                        <li class="drop-list-item"><a href="#">Smart Search</a></li>
                    </ul>
                </div>
                <input type="text" name="searchstring" class="form-control" style="z-index: auto">
            </div>
        </form>

req.body.searchstring工作正常。req.body.searchmethod.value失败,因为“searchmethod”未定义。searchmethod.text也失败。

根据评论。。有点难以理解这里到底发生了什么,一个代码笔或一些工作示例将帮助人们回答您的问题

一个基本错误在这里看起来很明显-节点不理解HTML属性-
req.body
将只包含
searchmethod
,如果表单中包含
name
属性为
searchmethod
的表单元素。那么
.value
将不必要,
req.body.searchmethod
将包含该值

例如


你应该发布相关的代码和确切的错误。认真地说,你希望我们能够从一段文字中找出你的HTML和代码吗?来吧。如果问题是关于代码和HTML的,请发布代码和HTML,否则问题需要在信息不足的情况下结束。
app.post('/', function(req, res) {
    res.send('Search Function: ' + req.body.searchmethod.value + ":" + req.body.searchstring); // this will eventually cause a return from SQL
    console.log("Search Function: " + req.body.searchmethod.value + ":" +  req.body.searchstring);
});
<form method="post" action="/" class="box">
    <input id="searchmethod" name="searchmethod" type="hidden" />
    <button id="searchbutton" ... >Name</button>
</form>
$('#searchbutton').on('click', function(){
    $('#searchmethod').val( $(this).text() );
});