[Vuejs]-Axios get request with parameter is not working

0๐Ÿ‘

โœ…

I do this as following:

  • when I need a get :
app.get('/detail/:id', function (req, res) {    
  //console.log(req.params.id);
  var url=urlDetail + "/" + req.params.id;
  axios.get(url)
  .then(function (response) {
   // result=response.data;
    res.render('database', { title: 'Detail' , dbs: response.data ,Version:pjson.version});
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
    //console.log("ici always");
  });
});
  • and when i need to post (req.body is a json):
app.post('/carto/demande', function (req, res) {   
  let data; 
  console.log(req.params);
  console.log(req.body);
  var url=urlCartoDemande;

  axios.post(url,req.body)
  .then(function (response) {


    data=response.data;
    res.render('carto',    { title : 'Demande' ,Version:pjson.version,mode:"resultat",data:data   }    );
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed

  });      
});    

Leave a comment