我想做一个AngularJS $ http请求函数,它将从服务器端调用此方法(使用JAX-RS Jersey),此方法为参数使用JSON并返回JSON作为结果,
@Path("/login")
@POST
@Consumes(value = MediaType.APPLICATION_JSON)
@Produces(value = MediaType.APPLICATION_JSON)
public Response login(User user) {
UserDao ud = new UserDao();
User dariDB = ud.login(user.getUsername(), user.getPassword());
dariDB.setPassword("");
return Response.ok(dariDB)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization")
.header("Access-Control-Allow-Credentials", "true")
.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD")
.header("Access-Control-Max-Age", "1209600")
.build();
}
你能帮助我在AngularJS假设Web服务的URL给了个例子,$http
请求功能是“http://localhost:8084/iec3/rest/user/login”?
你能告诉到目前为止,你已经尝试了什么? – h7r
HTTP({ \t \t \t \t方法: 'POST', \t \t \t \t URL: 'HTTP://本地主机:8084/IEC3 /休息/用户/登录', \t \t \t \t \t \t \t \t数据:{ \t \t \t \t \t \t尼姆:scope.nim, \t \t \t \t \t \t通:scope.pass, \t \t \t \t \t \t \t \t \t \t}, \t \t \t \t头:{ \t \t \t \t \t \t '内容类型': '应用/ JSON' , \t \t \t \t \t \t} \t \t \t \t})然后(函数successCallback(响应){ \t \t \t \t \t \t的console.log(response.data); \t \t \t \t \t \t},功能errorCallback(响应){ \t \t \t \t \t \t \t Flash.create( '危险', '什么错在这里', '定制级'); \t \t \t \t \t \t \t console.log(response。数据); \t \t \t \t \t}); 但我得到了错误 –
服务器响应到底是什么?角码是从同一个localhost:8084加载的? – h7r