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
編輯你的答案是否容易包含和說明?我是一個新手,它可能會幫助別人。 –