html - how to access javascript variables from a node.js file -


this might sound stupid have javascript script in html file. want store values of javascript variables using redis redis compatible node.js there way can access script variables of html file node.js , store them in redis?

directly can't. make ajax call(http://api.jquery.com/jquery.ajax/) node server, , save variables in redis (http://redis.io/commands/set) .

the ajax call choose depends on , if application restful or not. assuming want add variable redis, post call best suited. (https://api.jquery.com/jquery.post/ ).

as example lets post 2 variables node.

$.post("save_to_redis",{var1 : "example_value_1", var2: "example_value_2"},function(result){ //do returned } 

then in node (using express):

app.post('/save_to_redis',function(req,res){  var variable1 = req.body.var1; var variable2 = req.body.var2;  //call save redis var1 , var2  res.send("whatever like"); }); 

hope helps


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -