Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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
Html 单击表单提交按钮时触发远程引导模式,然后远程模式内容将显示表单数据?_Html_Node.js_Express_Twitter Bootstrap 3_Pug - Fatal编程技术网

Html 单击表单提交按钮时触发远程引导模式,然后远程模式内容将显示表单数据?

Html 单击表单提交按钮时触发远程引导模式,然后远程模式内容将显示表单数据?,html,node.js,express,twitter-bootstrap-3,pug,Html,Node.js,Express,Twitter Bootstrap 3,Pug,我很难找到一个方法来完成这件事 我正在使用Node.js、bootstrap3和express 我想从表格页开始。当用户填写表单时,他们单击submit。这里我想发射一个远程模式。(通过常规链接或按钮可以轻松完成此操作。) 这是一个帖子的开头。然后如何启动远程模式并将表单数据从post传递给它,以便在原始表单页面的模式窗口中显示一个新的远程页面,其中包含答案 以下是我的代码: 表格翡翠(封面表格翡翠): 远程模式Jade(尚未引用任何表单数据)answer.Jade: html body

我很难找到一个方法来完成这件事

我正在使用Node.js、bootstrap3和express

我想从表格页开始。当用户填写表单时,他们单击submit。这里我想发射一个远程模式。(通过常规链接或按钮可以轻松完成此操作。)

这是一个帖子的开头。然后如何启动远程模式并将表单数据从post传递给它,以便在原始表单页面的模式窗口中显示一个新的远程页面,其中包含答案

以下是我的代码:

表格翡翠(封面表格翡翠):

远程模式Jade(尚未引用任何表单数据)answer.Jade:

html
    body
        .modal-header
            button(type="button" class="close" data-dismiss="modal" aria-hidden="true")×
            h4.modal-title(id="myModalLabel") This Is An Awesome Title
        .modal-body 
            p This Body Is Great
        .modal-footer
            button.btn.btn-default(data-dismiss="modal") Close
用于路由的app.js:

...

app.get('/', routes.index);
app.get('/cover', cover.coverForm);
app.post('/cover', cover.doCover);

...
cover.js:

exports.doCover = function(req, res) {
    var mystockdata = [];
    console.log("Here is the symbol I got:    " + req.body.symbol);
    StockPrices.find({
        Symbol: req.body.symbol
    })
        .sort('Date')
        .exec(function(err, stockdata) {
            if (!err) {
                stockdata.forEach(function(stockdata) {
                    mystockdata.push({
                        "MarketDate": stockdata.Date,
                        "Open": stockdata.Open,
                        "High": stockdata.High,
                        "Close": stockdata.Close,
                        "Volume": stockdata.Volume
                    });
                });
                console.log("Here is the stock Data:    " + stockdata);
            } else {
                console.log(err);
            }
            res.render('answer', {});
        });
};
所以我的问题是,我该如何处理这个问题,以便在单击cover-form.jade上的submit时,我可以执行引导模式,并使用doCover函数启动模式内容的后期渲染

也许我也完全错了,不知道如何实现我想要的


非常感谢您的帮助。

能够让它正常工作,但不能远程工作

Bootstrap 3按钮默认为submit类型,所以我使用了一个标准按钮,它触发了一个模态

button#submit.btn.btn-primary(name='submit' data-toggle="modal" data-target="#myModal") Submit
然后,我将标准引导模式内容放在页面顶部:

.modal.fade(id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true")
  .modal-dialog.wide-modal
    .modal-content
      .modal-header
        button.close(type='button', data-dismiss='modal', aria-hidden='true') ×
        h4.myModalLabel.modal-title 
        | #{title}
      .modal-body
          #container(style="width:90%; height:400px;")
      .modal-footer
        button.btn.btn-primary(type='button', data-dismiss='modal') Close
然后真正的技巧是检查app.js触发的路由是post还是get。如果这是一篇意味着表单已提交的帖子,那么我使用jQuery来显示模式。否则,它会尝试显示,但会立即返回到表单。为此,我检查了一个仅在post函数(strikeprices)上呈现的变量:

.modal.fade(id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true")
  .modal-dialog.wide-modal
    .modal-content
      .modal-header
        button.close(type='button', data-dismiss='modal', aria-hidden='true') ×
        h4.myModalLabel.modal-title 
        | #{title}
      .modal-body
          #container(style="width:90%; height:400px;")
      .modal-footer
        button.btn.btn-primary(type='button', data-dismiss='modal') Close
script.
  $(document).ready(function(){

    if(#{strikeprices}){
      $('#myModal').modal('show')
    }

    $('body').on('hidden.bs.modal', '.modal', function () {
      $(this).removeData('bs.modal');
    });
  });