简体   繁体   中英

Meteor.js sending client variable to server

Basically want to do this... I thought a Meteor.method? but how would I go about that..? Thanks for help.

if(Meteor.isClient) {
var clientVar = getElementById("someId").value ;
}

if(Meteor.isServer) {
HTTP.call( 'GET', 'http://someurl.com/' + devId + '/' + '/' + utcTimestamp + '/' + 'clientVar', {
}, function( error, response ) {
  if ( error ) {
    future.return( error );
  } else {
    future.return( response ); 
 }
});
}

presuming on the client you'll have some sort of event that triggers the method you'd go

Meteor.call("useClientVar", clientVar, function(e,r) {//handle result});

and on the server you'd have

Meteor.methods({
  useClientVar(thing) {
    check(thing, String); // or whatever you're expecting
    // Do your HTTP call
  }
});

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