javascript - URL Query Parameters -


i'm facing problem.

i'm using node , express. index.html contains 2 inputs.

<form action="/profile" method="get">     <input id="variable1" name="variable1"  type="text" placeholder="..."> //xxx     select :  <select id="variable2" name="variable2">     <optgroup label="y">         <option value="variable">yyy</option>     </select> 

in profile.js got:

router.get('/profile', function(req, res){  var var1 = req.params.variable1; var var2 = req.params.variable2;  res.render('result'); } 

node renders result.html, url is

https://localhost:3030/profile?variable1=xxx&variable2=yyy 

the question how https://localhost:3030/profile/xxx/yyy instead of url above?

define route as: /profile/:var1/:var2

now access them using req.params:

var var1 = req.params.var1; var var2 = req.params.var2; 

updated answer:

though, may bit dirty, can try alternative if can't change url form submitted( though can using javascript on form submission ):

router.get('/profile', function(req, res){  var var1 = req.query.variable1; var var2 = req.query.variable2; res.redirect('/profile/'+var1+'/'+var2); }  router.get('/profile/:var1/:var2', function( req, res ){ var var1 = req.params.variable1; var var2 = req.params.variable2; res.render('result'); }); 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -