【发布时间】:2020-03-02 16:29:17
【问题描述】:
我正在从 ajax 调用一个 POST 方法,并希望它返回包含所有属性的 html 页面。
我的代码:
@RequestMapping(value = "/postMethod", method = {RequestMethod.POST, RequestMethod.GET})
public String getPage( @RequestBody(required=false) Object obj, HttpServletRequest request, Model model) throws Exception {
request.getSession().setAttribute("sess", cmp);
model.addAttribute("one", list);
model.addAttribute("two", list2);
model.addAttribute("object", new object());
return "htmlpage";
}
Ajax 调用:
var dataTosend = prepareDataToSend(data);
$.ajax({
url : getContextPath()
+ "/app/postMethod",
type : 'POST',
data : JSON.stringify(dataTosend),
contentType : 'application/json',
success : function(data) {
console.log(data);
//return to htmlpage
},
error : function() {
}
});
Myhtml 示例: 它不是一种形式:
<div id="page">
<!-- HEADER -->
<div id="header" class="inside content-wrapper">
<!-- MAIN CONTENT -->
<div id="main-content">
<div class="content">
<!-- accounts -->
<table>
<tr>
<td>
<label style="margin: 0 0 20px 0">Account</label>
</td>
<td> </td>
<td>
<select id="Dropdown" onchange="onDropdown()">
<option th:each="type : ${list}" th:value="${type.Id}" th:text="${type.Name}"></option>
</select>
</td>
</tr>
</table>
<!..............more div and other html data...........>
</div>
</div>
</div>
</div>
如果我对该方法进行 get 调用,它将返回到 html 页面,但是当调用后页面不重定向时,我想重定向到 htmlpage.html 并在 post 中设置所有属性,欢迎任何解决方案。
【问题讨论】:
-
I 页面正在使用 $().html(response) 呈现,但其他功能无法正常工作,因为脚本未加载且 url 也未更改。仍在搜索更多
-
您到底需要什么?用新属性重新加载整个页面?还是只是改变元素?
-
使用新属性重新加载整个页面。
标签: java jquery html spring rest