Ask coding questions

← Back to all posts
Node.js Getting Vaule
GatewayDuckYT

@Coder100 - Help me last time

Anyway guys i need help my code bellow see when i need to send a value from my .ejs file in node to my server file
i am using socket.io right now and here i wat i tryed to do but it no workes

views/freerank.ejs

server.js

functions

code

Answered by 19wintersp [earned 5 cycles]
View Answer
Voters
GatewayDuckYT
Comments
hotnewtop
19wintersp

What do you mean? The EJS is a template, which is rendered by the server and sent to the client. Are you trying to send data to the server from the browser? And shouldn't you put quotes around the <%= username %>?

19wintersp

I'd also suggest embedding values to be used in scripts into a <head> element rather than directly into the script.

GatewayDuckYT

@19wintersp ok bu how do i do it i want to send data from browser to server

just dont ask why ok

GatewayDuckYT

@19wintersp Whole Code For freerank.ejs

19wintersp

@GatewayDuckYT You're already using SocketIO, and your code seems to be correct. Do you get any browser console errors?

GatewayDuckYT

@19wintersp no but its no logging it to the file can i invite u to take a look?

19wintersp

@GatewayDuckYT

  1. Doesn't var socket = io() work just as well?
  2. Do you need to wait for SocketIO to connect?
  3. Don't use document.write.
  4. Extra closing brace ("}").
  5. HTML syntax is attribute="value", not attribute("value").
19wintersp
GatewayDuckYT