1

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

0

Depending on the results of your JSON, the following might be a good start:

$.getJSON("/getContents", function(data){
  var theRoom=$("#roomName").val();//textarea's value
  $.each(data.rooms, function( key, room) {
    if(room.title == theRoom)
       alert(room); 
  });
});
MikeB
  • 2,402
  • 1
  • 15
  • 24
  • getContents() sends a room not the entire collection. The problem is how to send room that has the same name as theRoom. I'll update the question to show getContents() – Manuel Mar 18 '14 at 00:30
  • you could send the requested room name to the server and do some server side querying – MikeB Mar 18 '14 at 00:35
  • How do I do that? I'm kind of new in Web applications – Manuel Mar 18 '14 at 00:37