0

I am trying to send HTTP GET request with email in params in following code:

$http.get('api/me', {
    params: {
        email: email
    }
});

but at backend I am receiving empty params i.e. request.params is blank. I tried the other format of HTTP request i.e.

$http({
    url: 'api/me', 
    method: "GET",
    params: {email: email}
});

but result is same i.e. empty params at backend.

My backend code:

User.findOne({ email: request.params.email }, function(error, user) {
    if (error) {
        throw error;
    } else if (!user) {
        response.json({
            message: "User doesn't exist.",
            status: 0
        });
    } else {
        response.json({
            message: "Successfully logged in.",
            status: 1,
            data: user
        });
    }
});
4

1 回答 1

1

您不应该使用参数来发送数据。相反,使用数据本身

$http({
    url: 'api/me', 
    method: "GET",
    data: {email: email}
});

然后在后端:

User.findOne({ email: request.email }, function(error, user) ...
于 2016-07-30T23:00:11.140 回答