TransWikia.com

passing data from javascript variable to an ejs variable

Stack Overflow Asked by Kevin Terblanche on January 1, 2022

i am getting a value in the variable items and this is in a script tag in html but i want to pass the data in the variable items to my back end to be used for storing in a db. i made selectedTeams a res.local.selectedTeams so i can use it in the ejs to try store the value of items and use it like that but it does not work

var transfer = $("#transfer1").transfer(settings1);
    // get selected items
    var items = transfer.getSelectedItems()
    console.log(items)
    for (let index = 0; index < items.length; index++) {
      <%= selectedTeams %>.push({_id: items[index].value})
    }


 res.locals.selectedTeams = []


router.post('/newseason', auth.adminAuth, async function(req, res, next) {
  console.log('..............................................................')
  console.log(selectedTeams)
});

so when the url gets called /newseason i would like the selected teams to be in the selected teams viariable

One Answer

You need to send ajax request to the api and pass the data with the api so it will be sent to the server. And from API in the backend code you can access selectedTeams in req.body.

Answered by jazeb007 on January 1, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP