如何使用request.query检索变量
在我的客户端代码中,我调用了getContents():
$.getJSon("/getContents", function(room){ theRoom=$("#roomName").val();//textarea's value ... });
在getContents()中,它位于服务器端代码(index.js)中,如何使用request.query或任何其他函数来获取theRoom(变量),以便我可以根据其标题获取Room的内容(房间)?
getContents();
var getContents=function(req,res){ ... var room=? ... roomCollection.findOne({name: room}, function(err,theRoom){... res.send(theRoom) }); ... }
您可以使用将其作为请求参数传递给$ .getJSON()
$.getJSON("/getContents", { room: $("#roomName").val() }, function (room) { //rest of code });
注意:不确定要读取请求参数的服务器端语法,请参阅此答案