邮政功能完成后重新加载

时间:2018-03-13 01:39:14

标签: javascript node.js

如何在按下具有POST功能的按钮后重新加载页面?

app.post('/upload', upload.single("file"), (req, res) =>{
// res.json({file: req.file});
res.redirect("/");
window.location.reload();
})

我已经尝试过window.loaction.reload()但它不起作用

<form action="/upload" method="POST" enctype="multipart/form-data">
  <span class="input-group-btn">
    <span class="btn btn-success" onclick="$(this).parent().find('input[type=file]').click();">
      <span class="glyphicon glyphicon-search"></span> 
      Browse
    </span>
    <input name="file" onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());" style="display: none;" type="file">
    <button type="submit" class="btn btn-primary" onclick="popup">
      <span class="glyphicon glyphicon-upload"></span>
       Upload
    </button>
  </span>
</form>

这是具有POST功能的表单。

页面位于主页的分支页面

:)

1 个答案:

答案 0 :(得分:2)

要完成此任务,您可以执行以下操作:

 # Note - Through trial and error discovery, it apparears Notepad accepts an extra whitespace
 # (possibly in the N+1 position) to help alignment. This matters not because thier viewport hides it.
 # There is no trimming of any whitespace, so the wrapped buffer could be reconstituted by inserting/detecting a
 # wrap point code which is different than a linebreak.
 # This regex works on un-wrapped source, but could probably be adjusted to produce/work on wrapped buffer text.
 # To reconstitute the source all that is needed is to remove the wrap code which is probably just an extra "\r".

 (?:
      # -- Words/Characters 
      (?:
           (?>                     # Atomic Group - Match words with valid breaks
                ( .{1,16} )             # (1), 1-N characters
                                        #  Followed by one of 4 prioritized, non-linebreak whitespace
                (?:                     #  break types:
                     (?<= [^\S\r\n] )        # 1. - Behind a non-linebreak whitespace
                     [^\S\r\n]?              #      ( optionally accept an extra non-linebreak whitespace )
                  |  (?<= [,.;:!/?] )        # 2. - Behind sepcial punctuation breaks
                  |  (?=                     # 3. - Ahead a linebreak or special punctuation breaks
                          \r? \n 
                       |  [-#%&*@_] 
                     )
                  |  [^\S\r\n]               # 4. - Accept an extra non-linebreak whitespace
                )
           )                       # End atomic group
        |  
           ( .{1,16} )             # (2), No valid word breaks, just break on the N'th character
      )
      (?: \r? \n )?           # Optional linebreak after Words/Characters
   |  
      # -- Or, Linebreak
      (?: \r? \n )            # Stand alone linebreak
 )