Reputation: 182
i'm new in NodeJS / Express..
so i created a simple CRUD program, but i get an error, the error is'nt in my query but in my route.
<a href='edit/#{data.id}'>Edit Data</a>
so if i tried to go to edit page, the url is localhost:3000/edit/(id)
my update form like this :
<form action='update-data'>
after submiting the form update, the url
supposed to be like this localhost:3000/update-data
but my url
like this : localhost:3000/edit/update-data
so the errors show is update-data
routes is not defined
how to solve my prblem? thanks
Upvotes: 0
Views: 45
Reputation: 707158
If you want your form submission to go to http://localhost:3000/update-data
, then change your form tag from this:
<form action='update-data'>
to this:
<form action='/update-data'>
When you have no leading /
or http://
on the URL, it becomes page relative which means the browser uses the path of the current page URL which in your case is localhost:3000/edit
so the browser just adds the update-data
to that and you ended up with localhost:3000/edit/update-data
. Change the form tag as I recommended and the URL will now be domain relative, not page relative so the path of the current page will not be used (only the domain and protocol of the current page will be used).
Upvotes: 1