我有一个控制器,处理URL studentEdit.html。当我传递给使用AJAX的控制器值'get'时,我需要重定向到另一个页面viewStudents.html,但没有任何反应。我留在同一页面上。该方法返回ModelAndView,但它为什么不重定向到另一个我不知道的页面。Spring MVC。重定向页面
我也试着设置网址为:
重定向:viewStudents.html和重定向:viewStudents
,但它并没有帮助。
@RequestMapping(value = "/studentEdit.html", method = RequestMethod.GET)
public ModelAndView getStudentProfile(@RequestParam(value = "get", required = false) String get) {
if(get != null && get.equals("get")) {
return new ModelAndView("redirect:/viewStudents.html");
} else {
ModelAndView mav = new ModelAndView("studentEdit");
return mav;
}
}
function getStudent() {
$.ajax({
type: "GET",
url: "/IRSystem/studentProfileEdit.html",
data: "get=" + 'get',
success: function(response) {
},
error: function(e) {
alert('Error' + e);
}
});
}
我将不胜感激任何信息,谢谢。
是否有你在服务器端这样做的原因?如果你实际上没有从服务器上检索任何数据,你应该只使用Javascript重定向。 – ntaylor2
您正在重定向AJAX请求本身。用这种方法重新定位页面是不可能的。 –
你可以通过添加一个头来解决这个问题,例如'X-Redirect-Url:/ my/redirect'到响应中,并在成功回调中对该值执行操作。如果你的环境当然让你。 – Bart