【问题标题】:i want to display submitted values?我想显示提交的值?
【发布时间】:2018-05-07 16:12:35
【问题描述】:

这是我的代码!!

var http = require('http');
var formidable = require('formidable');

http.createServer(function (req, res) {
  if (req.url == '/fileupload') {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
      res.write('File uploaded');
      res.end();
    });
  } else {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
    res.write('<input type="file" name="filetoupload"><br>');
   res.write('User name:<br> <input type="Text" Name="User Name"><br>');
   res.write('User Phone:<br><input type="Text" Name="User Phone"><br>');
   res.write('User E-mail:<br><input type="Text" Name="User E-mail"><br>');
    res.write('<input type="submit">');
    res.write('</form>');
    console.log();
    return res.end();

  }
}).listen(8080);

我想显示我在这段代码中使用的所有提交的值。 请帮我看看这段代码有什么问题!

【问题讨论】:

  • 你遇到了什么问题?
  • console.log(fields)res.write(JSON.stringify(fields));
  • 这在 Vue.js 之类的框架中真的很容易你在使用任何框架吗? 012.vuejs.org/guide/forms.html
  • 在此处显示您的日志
  • 其实我想将提交的值显示为一个表单,就像所有打印为表单名称的值一样,就像身份证或许可证一样

标签: javascript html node.js


【解决方案1】:

您可以在控制台中打印值:

console.log(JSON.stringify(fields));
console.log(files);

在网页上打印值:

res.write(JSON.stringify(fields));
console.log(files);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-29
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 2018-09-10
    • 2016-04-02
    • 1970-01-01
    • 2013-01-26
    相关资源
    最近更新 更多