0
我想发送一个AJAX请求到下面的路由器函数,分别使用参数start
和end
。在Node.js中传递参数GET Ajax
这些变量会影响我从请求中得到的结果。
router.get('/winnerlist', function(req, res) {
var db = req.db;
var start = "20140621";
var end = "20140623";
db.collection('userlist').find({"timestamp": {"$gte": start, "$lt": end}}).toArray(function (err, items) {
res.json(items);
});
});
这是我的AJAX GET调用
function populateWinners() {
// Empty content string
var tableContent = '';
// jQuery AJAX call for JSON
$.getJSON('/users/winnerlist', function(data) {
userListData = data;
console.log(data);
// For each item in our JSON, add a table row and cells to the content string
$.each(data, function(){
tableContent += '<tr>';
tableContent += '<td><a href="#" class="linkshowuser" rel="' + this.id2 + '" title="Show Details">' + this.id2+ '</a></td>';
tableContent += '<td>' + this.email + '</td>';
tableContent += '<td>' + this.code + '</td>';
tableContent += '<td><a href="#" class="linkdeleteuser" rel="' + this._id + '">delete</a></td>';
tableContent += '</tr>';
});
// Inject the whole content string into our existing HTML table
$('#winnerList table tbody').html(tableContent);
});
};
我已阅读this question,但我还没有想出如何使内Node.js的
我不明白这与我的问题有什么关系。代码从路由器获取结果,因为它是 –
哦,在这种情况下,应该在网址的查询字符串中将'start'和'end'作为参数。然后你可以通过调用req.query在服务器端检索它们。 – ejramire
编辑你的答案是否容易包含和说明?我是一个新手,它可能会帮助别人。 –