Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.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 使用node.js解析jade表单_Javascript_Node.js_Forms_Parsing_Pug - Fatal编程技术网

Javascript 使用node.js解析jade表单

Javascript 使用node.js解析jade表单,javascript,node.js,forms,parsing,pug,Javascript,Node.js,Forms,Parsing,Pug,我不知道如何从下拉列表中获取用户选择的项目。我的代码很短: extends layout block content p This is the CSV page p <select> <option value="domain">Domain</option> <option value="test">Test</option> <option value="random">Random&

我不知道如何从下拉列表中获取用户选择的项目。我的代码很短:

extends layout

block content
  p This is the CSV page
  p <select>
    <option value="domain">Domain</option>
    <option value="test">Test</option>
    <option value="random">Random</option>
    <option value="databases">Databases</option>
  </select>
  form(action="/csvuploader", method="post", enctype="multipart/form-data")
    label(for="payload") Select a file to upload:
    input#payload(type="file" name="myFile" accept="/*")
    br
    button#upload Upload
在文件上载表单的“操作”部分中引用的my/csvuploader文件中使用一些busboy方法,我已成功保存该文件。现在如何访问从下拉列表中选择的值

抱歉,如果这听起来像是一个非常愚蠢的问题,我是node.js和forms的新手。谢谢。

您需要将移动到元素内部,并为其命名:

form(action="/csvuploader", method="post", enctype="multipart/form-data")
  p This is the CSV page
  p
    select(name = "dropdown")
      option(value="domain") Domain
      option(value="test") Test
      option(value="random") Random
      option(value="databases") Databases
  label(for="payload") Select a file to upload:
  input#payload(type="file" name="myFile" accept="/*")
  br
  button#upload Upload

之后,您可以从req.body.dropdown中读取下拉列表的值。

感谢您的回答,但是req.body.dropdown在控制台中返回未定义的值。这和我正在使用的busboy有什么关系吗?@user2412643我假设您将使用它,它将填充req.body。如果你使用普通的服务生,你需要使用服务生。在“现场”,我使用的是连接服务生。唯一的问题是,我已经在'file'上有了req.busboy。。。保存从表单传递的文件。这会使事情复杂化吗@robertklep@user2412643不,那不是问题