0

I'm struggling with something here a bit. I've got some client-side code that requests to user to enter some data into a form.

I want to use this data (just two integer variables) on the server side.

How do I define these variables and access them?

2
  • you can pass variables while requesting server. No ? Commented Oct 16, 2017 at 10:46
  • 1
    Have you written any code attempting to do what you are asking? If so, please post it within your question. Commented Oct 16, 2017 at 13:22

1 Answer 1

1

you have to call a server side code from the client side, and pass the values, when you call the serverside code. Example:

function someClientSide(){
  //do smt here
  let v1 = foo
  let v2 = bar
  Meteor.call("updateTwoVariables", v1, v2)
}

Some resource for api methods: https://docs.meteor.com/api/methods.html

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Peter, Thanks! I've sort of figured it out using collections, but i think it's a bit of a work around. Does your method though all your to access v1 and v2 on the serverside using Meteor.call ?
Yes. If you use like this, you will get the the result in the terminal Meteor.methods({ updateTwoVariables(v1, v2){ console.log(v1, v2) } })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.