简体   繁体   中英

Passing a JavaScript object from EJS to Express

I'm incredably new at full stack development - so I might have some basic principles all wrong ...

I've buildt a small app with express and EJS. On my EJS page one can press a button and a JavaScript object is generated. My goal is for this object to be readable as a file from the www. Basically an API. The file should exists untill the button is pressed again - and then updated.

I've figured out how to get data from my MongoDB and pass it over to EJS - so my page is working just the way it should. But is it possible to pass data back to express and have it serve another template that just displays this javascript object (as a string I guess)?

Been googling for a few hours now, but I'm probably missing some terminology here. I hope someone can point me in the right direction (if there are any)!

I have no code to show you - since I don't know where to start :-/

In the script of your JS:

JSON.stringify your data -> POST Fetch/AJAX your data (first answer) -> Your server -> Client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM