Reputation: 1004
In my client-side code, I called getContents():
$.getJSon("/getContents", function(room){
theRoom=$("#roomName").val();//textarea's value
...
});
In getContents(), which is in the server-side code(index.js), how can I use request.query or any other function to get theRoom(variable) so that I can get the contents of a Room based on its title(theRoom)?
getContents();
var getContents=function(req,res){
...
var room=?
...
roomCollection.findOne({name: room}, function(err,theRoom){...
res.send(theRoom)
});
...
}
Upvotes: 0
Views: 103
Reputation: 388436
You can pass it as a request param to $.getJSON() using
$.getJSON("/getContents", {
room: $("#roomName").val()
}, function (room) {
//rest of code
});
Note: not sure about the serverside syntax to read the request parameter, see this answer
Upvotes: 3