【发布时间】:2019-10-27 21:13:51
【问题描述】:
如何显示对返回 HTML 的 Spring MVC 控制器的调用响应?在我的 Javascript 代码中,我对我的 Spring 控制器进行了 (GET) 调用。据我所知,调用的响应是 HTML。我想我需要用 Javascript 替换 'alert(response)' 来显示 html。
我的 Javascript 代码:
$('#parcelsTable').on( 'click', 'tr', function () {
var data = table.row( this ).data();
$.ajax({
url:"/parcel/showFormForUpdate",
type:"GET",
data:{parcelId:data.parcelId},
success: function(response){
alert(response)
}
});
} );
我在 Spring 中的控制器代码:
@GetMapping("/showFormForUpdate")
public String showFormForUpdate(@RequestParam("parcelId") int theId, Model theModel) {
Parcel theParcel = parcelService.findById(theId);
theModel.addAttribute("theParcel", theParcel);
return "parcel-form";
}
这里的“parcel-form”是一个模板的名称。
【问题讨论】:
-
您是否尝试使用该包裹表单打开一些对话框?
-
@barbsan,我需要显示不同的页面来更新包裹。
-
您可以将 HTML 作为内部 HTML 添加到页面上的任何容器中。例如,
$('#someId').html(responce); -
我的问题类似于这个未回答的问题:stackoverflow.com/questions/49103786/…
标签: javascript ajax spring-mvc