AngularJs:没有请求参数的HTTP POST
我试图使用$http服务向rest Api提交一个登录表单以发送请求,但是当我提交表单时,没有将请求参数传递给rest Api。这是我的代码:AngularJs:没有请求参数的HTTP POST,angularjs,json,http-post,angular-http,Angularjs,Json,Http Post,Angular Http,我试图使用$http服务向rest Api提交一个登录表单以发送请求,但是当我提交表单时,没有将请求参数传递给rest Api。这是我的代码: controller.formData = { username : $scope.formData.username, password : $scope.formData.password, }; $http({ method : 'POST', url : 'http://localhost:8080/multe-web/si
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);
});
你可以试试这个:-
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;
}
请参阅此项。HTML:
您需要使用函数调用$http,它不会被自动调用。它已经在提交表单时调用的函数中。这不是问题所在。请注意,问题中也没有html代码。我无法使用Jquery和api rest仅接受应用程序/json.updated,可能会有所帮助。您必须通过ng模型选择正确的数据。
$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){
});
<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>
$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);
})
}
};