如何在jqueryajax调用中使用springmvc重定向到视图
how to redirect to view in jquery ajax call using spring mvc
现在我的ajax调用:
$.ajax({
type: "POST",
url: contextPath +"/action",
cache:false,
dataType: 'text',
data: {Id:Id},
success: function(Result){
alert("in success ***");
dialog.dialog("close");
window.location.href = Result;
} ,
error: function(Result){
alert("in error");
}
});
我的控制器代码:
@RequestMapping(value="/action", method=RequestMethod.POST)
@ResponseStatus(value=HttpStatus.OK)
public @ResponseBody ModelAndView getApplyTemplatePage(@RequestParam("Id")int cId){
System.out.println("In apply template controller");
System.out.println("the value of id "+cId+" hostname"+hostName+"templateName"+tempName);
return new ModelAndView("applyTemplate");
}
现在我想重定向到applyTemplate.jsp页面。My Requirement正在通过ajax调用使用如何重定向到另一个jsp页面?
您可以在spring中发送一个带有位置标头的ResponseEntity,并相应地重定向。
public ResponseEntity<?> getApplyTemplatePage(@RequestParam("Id") int cId, UriComponentsBuilder b) {
UriComponents uriComponents = b.path("/applyTemplate.jsp").build();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uriComponents.toUri());
return new ResponseEntity<Void>(headers, HttpStatus.OK);
}
在ajax调用中,您可以获得位置标头并相应地重定向。
success: function(data, textStatus, xhr) {
window.location = xhr.getResponseHeader("Location");
}
相关文章:
- 通过javascript重定向html传递php变量
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 使用angular重定向到html页面
- 如何在chrome扩展中重定向到html页面
- 无法从jquery Mobile导航栏重定向到另一个页面
- ng视图外的链接重定向到ng视图内的页面
- 在phonegap应用程序内部重定向不起作用
- CORS-重定向到第二个GET正在接收的页面
- AJAX不会在文件上传后重定向到网页-POST方法
- 重定向时角度刷新浏览器
- 通过链接重定向不;我不在jstree中工作
- 根据select选项元素将表单重定向到不同的URL
- 通过JQuery重定向到另一个页面
- 重定向到“父窗口”
- 重定向iFrame中的父URL
- PHP-如何重定向到同一页面并更改DOM's
- chrome.tabs.update() 重定向到 'chrome-extension://invalid/'
- 如何在jqueryajax调用中使用springmvc重定向到视图
- 重定向到springmvc控制器而不打开页面
- 访问flash重定向属性(thymeleaf, springmvc)时出现Javascript错误