SSM的框架。
前台AJAX 通过URL到后台完全正常。
后台返回的时候,我把类型转成了JSON.但是就是接不到,进ERROR。
Controll层SRC:
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private IUserService userService;
@RequestMapping("/showUser")
public String toIndex(HttpServletRequest request,Model model){
JSONObject json = new JSONObject();
int userId = Integer.parseInt(request.getParameter("id"));
User user = this.userService.getUserById(userId);
json.put("user", user);
// model.addAttribute(, );
return json.toJSONString();
}
}
前台SRC:
$.ajax({
type: "GET",
url: "user/showUser",
data: {id:"1"},
dataType: "json",
success: function(data){
alert();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrown);
}
});