前台控制器:
var app = angular.module('myApp', []);
app.controller('LoginController', function ($scope, $http) {
$scope.submitForm= function(name,pw){
$http(
{
method : 'GET',
url : "http://localhost:8080/denglu/login.action",
params :{username:'1',password:'1',
/* data:JSON.stringify({data:data代表的是这个$http()对象中包含了将会被当作消息体发送给服务器的数据。通常在发送POST请求时使用。
'pageNum': pageNum,
'pageSize': pageSize,
'sort': sort,
'edition': edition */
}, // 传递数据作为字符串,从前台传到后台
}
).success(function (data) {
alert(data);
}).error(function() {
alert("登录失败");
});
}
})
后台action:
@RequestMapping("/login")
public ModelAndView login(String username,String password,HttpServletResponse response) {
ModelAndView m = new ModelAndView();
User user = new User();
user.setUsername(username);
user.setPassword(password);
System.out.println(username+password+"********************************");
User a = ilogin.login(user);
System.out.println(a+"********************************");
String msg="";
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(a != null){
msg="登录成功";
out.print(msg);
/*msg="登录成功";
m.addObject("msg", msg);
m.setViewName("index.jsp");*/
}
else{
msg="失败";
out.print(msg);
}
return m;
现在的情况就是action可以接收到前台传的参数,也能查到数据库中有值,但是前端界面一直走error,请大神指点,或者哪位大神给发下ajax的传接收数据的例子