2014-01-17 40 views
1

express.js閱讀PARAMS正確的語法,我有這樣一個URL作爲什麼對與node.js的

http://localhost:8080/siteinfo.json?site&locationid=1&companyid=1 

而且我想擊潰一個函數並傳遞?它的參數。什麼是正確的語法?

app.get('/siteinfo.json', getdata_hdlr.get_site_setup); 

回答

3

如果您還沒有定義在你的路線你PARAMS那麼這將是:

req.param('locationid'); 

但是你可以創建你的路由佔位符,如:

app.get("/product/:id", product.show); 

然後就是' id'參數在您的控制器中可用:

req.params.id 
2

查詢參數已經在請求對象中。

app.get('/siteinfo.json', function(req, res) { 
    console.log(req.query); 
    res.send("locationid="+req.query.locationid+"\ncompanyid="+req.query.companyid); 
});