0
我想送HTTP GET
要求與email
在params
:
$http.get('api/me', {
params: {
email: email
}
});
,但在後臺我收到空PARAMS即request.params
是空白。我試圖HTTP
請求即
$http({
url: 'api/me',
method: "GET",
params: {email: email}
});
的其他格式,但是結果是在後端相同,即空PARAMS。
我的後端代碼:
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
});
}
});
第一。後端,你應該期待一個「email」參數,其值不是「request.params」,就像你在你的問題中陳述的那樣。你能顯示你的後端代碼嗎? – cnorthfield
@papakia是的。你是對的。我誤解了格式。有沒有一種方法可以讓我把它作爲'request.params'或'request.headers'或'request.body'來獲取電子郵件(儘管我不需要'request.body',因爲它是一個GET請求)。 我也編輯了這個問題並添加了我的後端代碼。 – Rusty
您使用的是Express嗎?如果是這樣,請看這裏發佈的答案:http://stackoverflow.com/a/9243020/3453034 – cnorthfield