从AngularJS到Restful web服务的Post请求
我在AngularJS中创建登录页面,提交表单后,数据将发布到Restfull web服务以检查帐户是否存在,如果成功,返回“success”,如果失败,返回“Failed” 网络服务:从AngularJS到Restful web服务的Post请求,angularjs,Angularjs,我在AngularJS中创建登录页面,提交表单后,数据将发布到Restfull web服务以检查帐户是否存在,如果成功,返回“success”,如果失败,返回“Failed” 网络服务: @POST @Path(value = "login") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML) public String login(@FormParam("email")String e
@POST
@Path(value = "login")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public String login(@FormParam("email")String email, @FormParam("pass") String pass){
UserModel um = new UserModel();
Nguoichoi nc = um.find(email.trim(), pass.trim());
if (nc != null){
return "Success";
} else {
return "Failed";
}
}
AngularJS函数:
app.controller("LoginController", function($scope,$http) {
$scope.login = function(){
var encodeString = "email=" + this.email + "&pass=" + this.pass;
$http({
method: "POST",
url: "http://localhost:8080/HocvuiWebservices/rest/user/login",
data: encodeString,
headers: {'Accept':' text/plain', 'Content-Type': "application/x-www-form-urlencoded"}
}).success(function(data, status, headers, config){
console.log(data);
}).error(function(data, status, headers, config){
console.log(data);
console.log(status);
console.log(headers);
console.log(config);
console.log("Error submit form");
});
}
});
表格登入:
<form class="login-form" ng-submit="login()">
<div class="form-group">
<label for="exampleInputEmail1">Email: </label> <input
type="email" class="form-control" ng-model="email"
placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password: </label> <input
type="password" class="form-control" ng-model="pass"
placeholder="Password">
</div>
<div class="form-group">
<div class="checkbox">
<label> <input type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Loginp</button>
<a ui-sref="dangky" class="text-primary">Register</a>
</form>
电邮:
密码:
记得我吗
登录
登记
但当我提交表单时,post请求返回错误“error submit form”,虽然post请求成功连接到Restful web服务?您是否可以发布错误日志不应
this.email
和this.pass
be$scope.email
和$scope.pass
?API调用返回什么HTTP状态码?@konko:这是我的控制台。登录错误分支控制台.log(数据);控制台日志(状态);console.log(头文件);console.log(config);console.log(“错误提交表单”);=>null UIroute.html:96:6-1函数bd/@Lex:i更改了$scope.email…但出现了相同的错误