2014-01-17 26 views
0

我想知道這是否可以用Node.js和express.js完成。在我的傳入網址我有參數如。Node.js中的帶參數,然後添加到請求

http://localhost:8080/restaurant.html?siteid=7&locationid=8&companyid=7 

我想提取的查詢,然後將其附加到任何傳入的請求

,這樣當客戶端代碼調用我的JSON和我的路由器發送請求到

app.get('/siteinfo.json', function(req, res) { 
    console.log(company, site , location); 
    getdata_hdlr.get_site_setup(company, site , location); 
}); 

我可以將查詢參數傳遞給被調用的函數。

這樣做還是需要在我的客戶端代碼中執行此操作?

+0

你讀過http://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-node-js? –

+0

[使用req.query](http://expressjs.com/api.html#req.query) – Smitha

回答

1

您將需要使用req.query,然後將所有數據保存在req.session中,然後使用會話來提取所需的數據。

+0

我相信這需要'express.urlencoded()'中間件來解析查詢字符串。 – max