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()
    for (let index = 0; index < items.length; index++) {
      <%= selectedTeams %>.push({_id: items[index].value})

 res.locals.selectedTeams = []'/newseason', auth.adminAuth, async function(req, res, next) {

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!

Related Questions

How do I debug SwiftUI AttributeGraph cycle warnings?

5  Asked on December 30, 2021 by sindre-sorhus


RTD client in Python

1  Asked on December 30, 2021 by hunk


How to remove mongo specific fields from result (NodeJS, Mongoose)

5  Asked on December 30, 2021 by ararat-harutyunyan


Problem with ionic framework How can I solve?

0  Asked on December 30, 2021 by scar-fuentes


Random Forest Output

0  Asked on December 30, 2021 by charles-biwer


How to shift range of cells to unify values in rows

2  Asked on December 30, 2021 by jozef


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir