http获取请求与url中的奇怪字符\ t

时间:2017-08-23 15:23:37

标签: javascript angularjs node.js

大家好我已经尝试根据一组权限名称而不是他的id创建一个休息API请求(其余的API是在节点js中编写的,而我的前端是在angularjs中)。我只是拥有该组的名称,我需要发出API请求以获取基于id执行更新选项的ID。

我正在制作像

这样的获取请求
/api/organization_permissions_groups/getPermissionGroupId/?permissionGroup=Monitor%09%09%09%09%09%09%09%09

我的错误原因是%09%09%09%09%09%09%09%09

有没有办法删除?在nodej中,此部分被视为Monitor\t\t\t\t\t\t\t\t

orgnizationsController(angular js - client side)

 $scope.navigateToViews = function() {
    var btn = event.currentTarget;          
        groupName = btn.parentNode.parentElement.innerText;

    if(groupName!=null){
        console.log("groupName ",groupName);
        $http.get('/api/organization_permissions_groups/getPermissionGroupId/',
                   {params: {permissionGroup: groupName}})
          .success(function (data) {
            if(data!=undefined && data != null){
                $rootScope.groupId=data;
                console.log("controllerScope.id ",$rootScope.groupId);
            }
        });
    }

    console.log("controllerScope.id views ",$rootScope.groupId);
    $state.go('app.organizationViews');

}

在我的restApi for OrganizationPermissionsGroupsController.js中我有

OrganizationPermissionsGroupsController.prototype.setRoutes = function (express) {
    var router = express.Router();

router.route('/getPermissionGroupId/')
        .get(passport.authenticate('jwt', {session: true}) this.getOrganizationPermissionsGroupByName);
}

    OrganizationPermissionsGroupsController.prototype.getOrganizationPermissionsGroupByName = function (req, res, next) {


createLog('info', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'getOrganizationPermissionsGroupByName', 'inicio');

var data = req.query.permissionGroup.toString();
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'getOrganizationPermissionsGroupByName', 'data 1', data);

var replaced=data.toString().replace('\t', '');
if (isEmptyObject(replaced)) {
    res.status(400).send({error: errorMessage.emptyBody});
    return;
}

createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'getOrganizationPermissionsGroupByName', 'data 2', replaced);
Database.OrganizationPermissionsGroups.getOrganizationPermissionsGroupById(replaced).then(function (groupId) {
    if (groupId.length == 0) {
        res.status(404).end();
    } else {
        res.status(200).send(groups[0]);
    }
}).catch(function (e) {
    createLog('error', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'getOrganizationPermissionsGroupByName', e);
    res.status(500).send(e);
});

    }

日志:

2|wscontro | [2017-08-23 17:38:40.326] - info: /opt/wscontroller/wscontroller-api/routes/organization_permissions_groups OrganizationPermissionsGroupsController NA getOrganizationPermissionsGroupByName inicio
2|wscontro | [2017-08-23 17:38:40.327] - debug: /opt/wscontroller/wscontroller-api/routes/organization_permissions_groups OrganizationPermissionsGroupsController NA getOrganizationPermissionsGroupByName data 1 "Monitor\t\t\t\t\t\t\t\t"
2|wscontro | [2017-08-23 17:38:40.328] - debug: /opt/wscontroller/wscontroller-api/routes/organization_permissions_groups OrganizationPermissionsGroupsController NA getOrganizationPermissionsGroupByName data 2 "Monitor\t\t\t\t\t\t\t"
2|wscontro | [2017-08-23 17:38:40.329] - info: /opt/wscontroller/wscontroller-api/routes/organization_permissions_groups OrganizationPermissionsGroupsDatabase NA getOrganizationPermissionsGroupById inicio
2|wscontro | [2017-08-23 17:38:40.337] - error: /opt/wscontroller/wscontroller-api/routes/organization_permissions_groups OrganizationPermissionsGroupsDatabase NA getOrganizationPermissionsGroupById { error: invalid input syntax for uuid: "Monitor                        "

2 个答案:

答案 0 :(得分:0)

这一行之后

if(groupName!=null){

你应该用''替换\ t那样的。

groupName=groupName.replace('\t', '');

答案 1 :(得分:0)

使用trim() method

 $scope.navigateToViews = function() {
    var btn = event.currentTarget;          
    var groupName = btn.parentNode.parentElement.innerText;
    groupName = groupName.trim();