在req.body(express,jade)中找不到提交按钮名称

时间:2017-02-15 03:18:41

标签: node.js express pug

我只是为了自己的兴趣学习node.js。 我的node.js来源jade中存在问题。

有2个问题

  1. 当我点击“保存”按钮时,我在req.body

  2. 中找不到“保存”
  3. 点击按钮后,我收到了一条消息

    throw new Error('Can\'t set headers after they are sent.');

  4. 玉源

    doctype html
        html
          head
            meta(charset='utf-8')
            title My Memo
          body
        h1 My Memo
        artcle
          form(method='post', enctype='multipart/form-data', action='/process/registerMemo')
            p
              label Author
              input(type='text', name='userName')
            p
              label Date
              input(type='date', name='writeDate')
            p
              label Description
              textarea(row='5', clos='40', name='usersNotes')
            p
              label Picture
              input(type='file', name='imgfile')
            p
              input(type='submit', value='save', name='save')
              input(type='submit', value='close', name='close')
    

    JSP来源

    app.post('/process/registerMemo', function(req, res) {
        console.log('/process/registerMemo called');
        if (req.body.save)
            console.log('save button touched');
        else
            console.log('exit button touched');
        upload(req, res, function(err) {
            if (err) {
                res.end("update failed");
            }
    
            var userName = req.body.userName;
            var writeDate = req.body.writeDate;
            var userNotes = req.body.usersNotes;
            console.log(req.body.userName);
            console.log(req.body.writeDate);
            console.log(req.body.usersNotes);
            console.log(req.body);
            if (req.body.save) {
                console.log('save button touched')            
                // var fileCount = files.length;
                // for( var i = 0; i < fileCount; i++){
                //   var savedFileName = files[i].filename;
                // }
                fs.writeFile('data/' + userName + '_' + Date.now(),
                  userName + '/' + writeDate + '/' + userNotes, function(err) {
                      if (err) {
                          console.log(err);
                          res.status(500).send('Internal Server Error');
                      }
                      console.log('/public/myMemoResult should be called')
                      res.redirect('/public/registerMemo');
                  })
            } else {
                // close button call
                console.log('close button touched')
                res.redirect('/public/myMemoResult');
            }
        });
    });
    

0 个答案:

没有答案