<form class="form-box" action="/correction" method="POST">
<h4>수정하기</h4>
<input name="id" value="<%= result._id %>" style="display: none">
<input type="text" name="title" value="<%= result.title %>">
<input type="text" name="content" value="<%= result.content %>">
<button type="submit">전송</button>
</form>
form의 action태그를 /correction으로만 되어 있어서 전송버튼을 누를 때 Cannot GET /correction 오류가 발생한다. 이 뜻은 서버로 /correction에 대한 get 요청을 보내는 라우터를 찾지 못할 때 발생하는 오류이다.
Cannot GET /correction 오류는 app.get('/correction/:id') URL 파라미터를 통해 :id로 get 요청을 받으니 action 태그도 똑같이 수정해야 한다는 뜻이다.
<form class="form-box" action="/correction/<%= result._id %>" method="POST">
<h4>수정하기</h4>
<input name="id" value="<%= result._id %>" style="display: none">
<input type="text" name="title" value="<%= result.title %>">
<input type="text" name="content" value="<%= result.content %>">
<button type="submit">전송</button>
</form>
URL 파라미터를 ejs 문법으로 수정하면 글을 수정할 수 있다. 하지만 PUT가 안되는 이유는 HTML폼에서 PUT이나 다른 메서드를 지원하지 않는다. 폼 요소에서 지원하는 메소드는 GET, POST요청 뿐이다.
결국 URL 파라미터 문법을 이용해 주소를 정확히 적지 않아서 발생하는 오류.
'Node.js' 카테고리의 다른 글
MongoDB 비밀번호 암호화 (2) | 2024.02.06 |
---|---|
list.ejs - 삭제기능 구현 오류 (0) | 2024.02.06 |
ejs - 문법 오류 에러 (0) | 2024.02.04 |
server.js - urlParams 오류 수정 (0) | 2024.02.04 |
list.ejs - css 적용 안됨 오류 해결 (0) | 2024.02.02 |