More Client-Side, Server-Side Communication Questions
Heya, Ray again. I have another Server-Side, Client-Side problem that needs a bit of help. So I need to assign a variable “name” with information from localStorage so that it finds the correct document name in the database, but I don’t know how to send it to the function from client-side to server-side.
My relevant code (not sharing the Repl for security reasons):
Server Side Index.js
async function dbGetMultiplier(db) { //The “name” variable is missing, and I need to give it data from localStorage. const docRef = db.collection('users').doc(name); const doc = await docRef.get(); let output = []; let n = await doc.data(); output.push({ m1: n.multiplier1, m2: n.multiplier2, m3: n.multiplier3, m4: n.multiplier4, m5: n.multiplier5 }); return output; } app.get('/get-multipliers', async (_, res) => { res.send(await dbGetMultiplier(db)); });
Client Side Index.js
const data = (await fetch('/get-multipliers', { method: 'GET' }).then(r => r.json()))[0]; const m1 = data.m1; const m2 = data.m2; const m3 = data.m3; const m4 = data.m4; const m5 = data.m5; let totalMult = ((m1 * 10) + (m2 * 10) + (m3 * 10) + (m4 * 10) + (m5 * 10)) / 10;
That’s all the relevant information. Can someone help find the problem. Thanks,
~ Ray
For business development it is very important to attract new customers and retain those that are there. To ensure that the client always has reliable support we use https://wow24-7.io/saas, our company's reputation is very important to us and that's why we choose the best outsourcing of customer support. Behind every big business there should be a strong saas support team.
Looks like I'm #1
https://v2-pumpkingame.rayhanadev.repl.co/leaderboard
but if he isn't like spamming the post, and instead silently spamming, mods can't really do anything about it
ahhhhhh use the other function I gave you
and in your client side:
const data = (await fetch('/get-multipliers', { method: 'GET', headers: { 'content-type': "application/json" }, body: JSON.stringify({ name: <insert-the-name-variable-you-know> }) }).then(r => r.json()))[0]; const m1 = data.m1; const m2 = data.m2; const m3 = data.m3; const m4 = data.m4; const m5 = data.m5; let totalMult = ((m1 * 10) + (m2 * 10) + (m3 * 10) + (m4 * 10) + (m5 * 10)) / 10;
backend:
async function dbGetMultiplier(db, name) { //The “name” variable is missing, and I need to give it data from localStorage. // do something with it ig const docRef = db.collection('users').doc(name); const doc = await docRef.get(); let output = []; let n = await doc.data(); output.push({ m1: n.multiplier1, m2: n.multiplier2, m3: n.multiplier3, m4: n.multiplier4, m5: n.multiplier5 }); return output; } app.get('/get-multipliers', async (req, res) => { res.send(await dbGetMultiplier(db, req.body.name)); });
fair enough. I’ll post it. Think you can help?
Cannot read property multipier1 of undefined
. The error could be something wrong in the way I set up the variable or it could be something else in the code. (Which is why I said IDK, I don’t want to confuse anyone who tries.) So um, does that make sense?req.body.name
is undefined (in the app.get). That is the cause of all the errors! So my question is how do I fix it?
Hey! I also recently tried to find good desk-alert software. It took me a lot of time to search, but in the end I found what I was looking for for so long, read this https://www.alert-software.com/blog/workplace-safety-communications .
With this application, it is much easier to monitor the work of employees and if there is something that needs to be notified to everyone, you can simply send a notification to the desktop. It is very comfortable!