我无法使用 Ajax 成功方法打开 Spring 控制器方法给出的
ModelAndView
响应。
Spring控制器方法:
@RequestMapping (value="setupDbEdit.htm", method=RequestMethod.GET)
ModelAndView setupABC(@RequestParam String db_id){
System.out.println("**hello world**"+db_id);
ModelAndView modelAndView=new ModelAndView("editDB");
request.setAttribute("dbID", db_id);
return modelAndView;
}
@RequestMapping (value="editDB.jsp", method=RequestMethod.GET)
ModelAndView addCustomerSetupABC(){
ModelAndView modelAndView= new ModelAndView("editDB");
return modelAndView;
}
Ajax代码:
$("#editDb").click(function(e){
$.ajax({
type: 'GET',
'url': 'http://localhost:8080/Test_ReportingUI/setupDbEdit.htm',
data: {db_id: dbID},
dataType: 'html',
success: function(response){
alert(response);
},
timeout: 10000,
error: function(xhr, status, err){
}
});
});
editDB.jsp
(我要打开的页面):
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script>
alert("hellow");
</script>
<%
String strDBID=(String) request.getAttribute("dbID");
out.println(strDBID+"<br><br>");
%>
This is edit screen for DB details...
</body>
</html>
我不想在弹出窗口中打开此页面,而是想通过替换旧页面来在同一页面上打开它。
在同一页面上,您应该指定返回的 html 文本应注入的目标。例如
<div id="result"/>
然后在
success
处理程序上加载内容
success: function(response){
$("#result").html(response);
},