0
我無法從請求中獲取參數。在這裏我的代碼 -Rails&Angular:無法獲取參數
JS代碼
loginApp = angular.module("loginApp",[]);
loginApp.controller("loginController",function($scope,$http){
$scope.username = "";
$scope.password = "";
$scope.login = function(){
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
username = $scope.username
password = $scope.password
params = {username: username, password: password};
$http.post('api/login',params)
.then(function(response) {
$scope.myWelcome = response.data;
});
}
});
如你我想提出一個POST請求API /登錄。
控制器代碼 -
def login
username = params[:username]
password = params[:password]
puts username.inspect
puts password.inspect
末
結果 -
Started POST "/api/login" for 127.0.0.1 at 2017-02-05 00:20:31 +0900
Processing by ApiController#login as HTML
Parameters: {"{\"username\":\"jsxbhjcxb`\",\"password\":\"jcbsjcb\"}"=>" [FILTERED]"}
nil
nil
我不知道爲什麼它顯示爲零。對不起,我新來的角和軌。 請幫忙。您在JSON格式發送數據
由於它是真正的工作。 – RajSharma