今天用Spring写了一个功能,是在页面进行注册,如果注册成功,则跳转到A页面,失败则跳转到B页面。使用RedirectAttributes设置页面跳转过程中的参数,使用return "redirect:/hello";
进行跳转。简写了一个代码如下:
@RequestMapping(value="/register",method=RequestMethod.POST)
public String register(@RequestBody RequestRegister request, RedirectAttributes redirectAttributes){
return "redirect:/hello";
}
可是在前端请求之后却发现页面不向想象中那样跳转,但是审查元素会发现已经请求了相应的URL,就是没有跳转!!!如下:
有人知道是哪里写错了吗?
看到
jquery
应该是通过Ajax
进行请求的这个接口通过
Ajax
请求的数据返回的是字符串,不会进行跳转如果要需要重定向,在
Ajax
请求的成功回调中执行window.location='/hello'
就可以了