2016-06-29 2 views
0

를 보내지 않습니다 :AngularJS와 내가 다음 코드 한 HTTP POST 요청

application.controller('userLoginController', function($scope,$http){ 
window.document.title = "User Login"; 
$scope.form = { username: '',password: ''}; 
$scope.submitLogin = function(){ 
    var config = { 
     method: 'POST', 
     url: 'server_app/login.php', 
     data: { 
      'username' : $scope.form.password, 
      'password' : $scope.form.password 

     } 
    }; 
    var request = $http(config); 
    request.then(function (response){ 
     $scope.errorMessage = response.data; 
    },function(error){ 
     $scope.errorMessage = error.data; 
     }) 
    } 
}); 

나는 그 같이 백엔드 서버로 POST 요청을 보내려고했다하십시오 내 데이터를 제출 한 후

var_dump($_POST); 

을 버튼 $ _POST를 다시 배열로 가져와야합니다. 그 Insteed 나는

array (size=0) 
    empty 

내 HTML 코드를 보면 그런 식으로 얻을 : 여기에 문제가 표시되지 않습니다

<input placeholder="Login" class="searchProduct" autocomplete="off" name="username" type="text" ng-model="form.username"><br> 
<input placeholder="Password" class="searchProduct" autocomplete="off" type="password" name="password" ng-model="form.password"/> 
<div class="button" ng-click="submitLogin();">Login</div> 

..

답변

0

각도 코드가 정상적으로 보이는 것처럼 아래 파일의 데이터를 받고 싶습니다.

$ params = json_decode (file_get_contents ('php : // input'), true);

+0

정말로 감사합니다. 그러나 나는 왜 그런 말을해야합니까? 예를 들어 Jquery를 사용하는 것은 var_dump ($ _ POST)입니까? –

+0

formet enctype = "multipart/form-data"로 양식 데이터를 보내면 json으로 데이터를 보내므로 file_get_contents ('php : // input')를 사용해야하므로 $ _POST로받을 수 있습니다. –

+0

알았어요! 고맙습니다! –

0

당신은 아래의 코드를 사용할 수 있습니다

$http.get('/someUrl', config).then(successCallback, errorCallback); 
$http.post('/someUrl', data, config).then(successCallback, errorCallback); 
+0

고맙습니다.하지만 여전히 내 질문에 대답하지 않으므로 왜 작동하지 않는지 알고 싶습니다. –