敢问各位req.body.[ID] 获取不到有几种可能性呢?
发布于 11 年前 作者 xlkmuu 5892 次浏览 最后一次编辑是 8 年前

如标题,今天出的问题,input标明了 id = 'name' 但是req.body.name 就是获取不到。请帮忙

5 回复

尝试 打印 console.log(req.body) 看看。

嗯,打印了

body = {}

以下为标签:

<form class="form-signin" action="/login" method="POST">
<fieldset>
<h2 class="form-signin-heading">请登陆</h2>
      <% if(locals.error){ %>
         <div class="alert alert-error">
              <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong><%= error %></strong>
          </div>
       <% } %>
<input id='name' type="text" class="input-block-level" placeholder="用户名">
<input id='password' type="password" class="input-block-level" placeholder="密码">
<label class="checkbox">
<input id='isRemember' type="checkbox" value="remember-me"> 记住我
</label>
<button class="btn btn-large btn-primary" type="submit">登录</button>
<button class="btn btn-large btn-primary" type="submit">注册</button>
</fieldset>
</form>
那为什么body是空的呢

问题找到了 <form> <input> 标签必须都要要有name属性,POST才能有值

一般情况下,表单都是以name的名值对来取值的。

回到顶部