2016-07-30 98 views
0

我想送HTTP GET要求與emailparams

$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 
     }); 
    } 
}); 
+0

第一。後端,你應該期待一個「email」參數,其值不是「request.params」,就像你在你的問題中陳述的那樣。你能顯示你的後端代碼嗎? – cnorthfield

+0

@papakia是的。你是對的。我誤解了格式。有沒有一種方法可以讓我把它作爲'request.params'或'request.headers'或'request.body'來獲取電子郵件(儘管我不需要'request.body',因爲它是一個GET請求)。 我也編輯了這個問題並添加了我的後端代碼。 – Rusty

+0

您使用的是Express嗎?如果是這樣,請看這裏發佈的答案:http://stackoverflow.com/a/9243020/3453034 – cnorthfield

回答

0

你不應該使用PARAMS發送數據。相反,利用數據本身

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

,然後在後端:

如果電子郵件變量分配給它的值的所有檢查
User.findOne({ email: request.email }, function(error, user) ...