【发布时间】:2014-03-19 05:30:10
【问题描述】:
我正在使用 node.js express 来构建简单的 rest API,我已经构建了一个类似的 API
app.get('/sites/:site/:building/:floor',function(req,res){
var building = req.params.building, floor = req.params.floor, site = req.params.site;
console.log('query site ',site,building, floor);
.....
}
当客户端在 angular.js 中进行 AJAX 请求时
$http.get('/sites/london')
.success(function(data) {
}).error(function(data, status, headers, config) {
});
服务器不会响应这种 URL,除非我将 express API 更改为
app.get('sites/:site',function(){})
app.get('sites/:site/:building',function(){})
app.get('sites/:site/:building/:floor',function(){})
但是上面的方法太繁琐了,不知道有没有可能一句话就建好APIapp.get('sites/:site/:building/:floor',function(){})
【问题讨论】: