Ton*_*tez 1 mongodb restful-url node.js express angularjs
我正在使用Express,mongodb和Angular创建一个应用程序,我在MongoDB中的一个文件的标识符为 _id ='20161007/COMPANY-00/CL/01-01'
我试图通过REstful API使用标识符从Angular获取数据:
var _id = '20161007/COMPANY-00/CL/01-01';
this.$http.get('/api/datadays/' + _id)
.then(response => {....}
Run Code Online (Sandbox Code Playgroud)
但结果是:
angular.js:11881 GET http:// localhost:9000/api/datadays/20161007/COMPANY-00/CL/01-01 404(未找到)
有没有办法在标识符中使用斜杠来处理node/express中的restful API?
谢谢
您应该查看Encode URI Component和Decode URI Component.
前端代码:
var _id = encodeURIComponent('20161007/COMPANY-00/CL/01-01');
this.$http.get('/api/datadays/' + _id)
.then(response => {....}
Run Code Online (Sandbox Code Playgroud)
后端代码:
app.get('/api/datadays/:id', function(req, res) {
let id = decodeURIComponent(req.params.id)
...
})
Run Code Online (Sandbox Code Playgroud)