我尝试使用$ http服务向其余的Api提交登录表单以发送请求,但是当我提交表单时,没有请求参数传递给。这是我的代码:
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);
});
答案 0 :(得分:0)
你可以试试这个: -
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)
$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){
});
参考。
答案 2 :(得分: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 :
$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);
})
}
};