0

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)
});
...
}
Manuel
  • 976
  • 3
  • 9
  • 21

1 Answers1

3

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

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531