koa-router post請求接收的參數為空


注:koa-router路由和koa-bodyparser中間件  post請求中參數為空。

 

 

頁面代碼

<!DOCTYPE html>
<html>
<head>
    <title>新增數據</title>
</head>
<body>
    <h1><%= title %></h1>
    <form method="post" action="/addCommit">
        <span>名字:</span>
        <input type="text"/>
        <span>描述:</span>
        <input type="text"/>
        <button type="submit">提交</button>
    </form>
</body>
</html>

上面這段代碼,試了好多次,參數都接收不到。然后各種百度,找了半個多小時。還是沒效果。

因為學過java 有點java基礎  發現上面input輸入框少了點 東西 "name"屬性,然后就去試了一下。結果是成功了

<!DOCTYPE html>
<html>
<head>
    <title>新增數據</title>
</head>
<body>
    <h1><%= title %></h1>
    <form method="post" action="/addCommit">
        <span>名字:</span>
        <input type="text" name="nane"/>
        <span>描述:</span>
        <input type="text" name="message"/>
        <button type="submit">提交</button>
    </form>
</body>
</html>

不過 ,接收不到參數的原因有很多,這只是其中一個原因,而且還是最基礎的......

總結:學習某種新技術時,要學會和其它技術去比較,“去類比“ 。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM