0

this might sound stupid but i have a javascript script in a html file. I want to store the values of the javascript variables using redis but redis is only compatible with node.js Is there a way i can access the script variables of the html file from the node.js and then store them in redis?

1
  • no. I assume your values are on client side on browser. You could do an API call to your node.js server though. Commented May 11, 2015 at 15:34

1 Answer 1

1

Directly you can't. You could make an ajax call(http://api.jquery.com/jquery.ajax/) to your node server, and then save the variables you like in redis (http://redis.io/commands/SET) .

The ajax call you could choose depends on what exactly you would like to do and if your application is RESTful or not. Assuming you want to add a variable to redis, a POST call is best suited. (https://api.jquery.com/jquery.post/ ).

As an example lets say you post two variables to your node.

$.post("save_to_redis",{var1 : "example_value_1", var2: "example_value_2"},function(result){
//do something with what is 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 to redis for var1 , var2

res.send("whatever you like");
});

Hope this helps

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

Comments

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.