2016-08-03 3 views
2

요청을 보내기 위해 $ http 서비스를 사용하여 나머지 Api에 로그인 양식을 제출하려고하지만 양식을 제출할 때 요청 매개 변수가 전달되지 않습니다.AngularJs : 요청 매개 변수가없는 HTTP POST

controller.formData = { 
          username: $scope.formData.username, 
          password: $scope.formData.password, 
          } 

    sendRequest(controller.formData).success(function(data) { 
     console.log(data); 
    }).error(function(data) { 
     console.log(data); 
    }) 


    function sendRequest(data) { 

     var sendRequest = $http.post("http://localhost:8080/multe-web/signin", data); 
     return sendRequest; 
    } 
+1

, 그것은 늘 자동으로 호출된다. –

+0

양식을 제출할 때 이미 호출 된 함수 안에 있습니다. 이것은 문제가되지 않습니다. – ezio88

+0

질문에, 또한 질문에 HTML 코드도 없다는 것을 언급하십시오. –

답변

0

: 이것은 내 코드입니다.

+1

올바른 코드 들여 쓰기를하십시오. 코드를 읽을 수 없음 – ddb

+0

@mayank가 작동하지 않습니다. – ezio88

0
$http.post(
    authUrl+'/things', 
    $.param(requestData), 
    { 
     headers: 
     { 
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' 
     } 
    } 
) 
.success(function(data, status){ 

    deffered.resolve(data, status); 
}).error(function(data,status){ 

}); 

이 참조 -이 : 당신이 시도 할 수

controller.formData = { 
username : $scope.formData.username, 
password : $scope.formData.password, 
}; 
$http({ 
    method : 'POST', 
    url  : 'http://localhost:8080/multe-web/signin', 
    data : controller.formData, 
    headers : { 'Content-Type': 'application/json' } 
}) 
.success(function(data) { 
    console.log(data); 
}); 

enter image description here

+1

"authUrl"이란 무엇입니까? – ddb

+0

Jquery를 사용할 수 없으며 내 API 휴식은 application/json 만 허용합니다. – ezio88

0

HTML :

<form id="your_form" name='your_form' ng-submit="check.submit(your_form)"> 
    <input type="password" ng-model='passValue'> 
    <input type="text" ng-model='userNameValue'> 
</form> 

Controllers.js는 :

당신은 함수를 사용하여 $ HTTP를 호출 할 필요가
$scope.check = { 
    submit : function() { 
     var data; 
     data = { 
      'username' : $scope.userNameValue, 
      'password' : $scope.passValue, 
     }; 
     var request = $http({ 
      method: 'POST', 
      url:  'http://localhost:8080/multe-web/signin', 
      data: data, 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }); 
     request.then(function(data) { 
      console.log(data); 
     }); 
     request.catch(function(data) { 
      console.log(data); 
     }) 
    } 
}; 
+0

시도는하지만 작동하지 않습니다. – ezio88

+0

이 업데이트되었습니다. 아마도 도움이됩니다. ng-model을 통해 올바른 데이터를 선택해야합니다. –