注: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>
不過 ,接收不到參數的原因有很多,這只是其中一個原因,而且還是最基礎的......
總結:學習某種新技術時,要學會和其它技術去比較,“去類比“ 。
